ARTH - Task 14.2 ???????

ARTH - Task 14.2 ??????

*Task Description*??

?? *14.2* Further in ARTH - Task 10 has to create an Ansible playbook that will retrieve new container IP and update the inventory. So that further Configuration of the Webserver could be done inside that Container.

This is a very big task in this task firstly I would install Ansible Docker in my system and then Pull the image of docker from the Dockerhub. after then we have to set up our ansible to perform the task like make an ansible_conf file in which we tell our Inventory file In this tasks we use Inventory two time Because in this task we run two diff Playbook on Two Diff OS The First playbook is run on our localhost so there is no need of Inventory file for that we can write this on our playbook that we have to run this on Localhost.

And the second Playbook is run after when our first playbook is run successfully without any error and our first playbook creates an inventory file for our second Playbook or it can also create our second os on which we have to run our second playbook. after running the second playbook we get our requirement for this task as we need.

So let's see some main terminology of this two playbook and also what we write in these two playbook

Let's talk about our first playbook This is a playbook that we have to run over the Localhosts because your requirement is to run the docker container by running this playbook so on localhost we have docker setup and also the same image that we have to use our doing our practice and in these, we only pass one variable that is our container name we need this as a variable because it is necessary to have diff name of the container to launch it must be that same name of container neither be running nor in stop state so we give as a variable name. After that, we use the Ansible module name is docker_container this is used to create a docker container via ansible so we have to provide it image name that we use to create a container and the name of the container that we want to five and also port no on which we can expose it service and we create a specific image in which we have to setup

The SSh server with the permanent start of there service means when we launch a container with that image that must have a running service of SSH server it can take SSh after creating as we know Ansible use only ssh method to connect to os and then perform its works so it is must that Launched container must have an SSH server running and it can easily connect to us. and after that in the playbook, we have to get the info of launched container like IP address and all so for that we also have an ansible module that is docker_conatiner_info by which we can take all the info launched docker and after that, we have got the IP address of that Container so that by taking this IP we can create a new inventory file in which we have IP of our Container with there user name and password we can use ansible module for creating an inventory file that can fetch the IP with the help of docker_container_info module now we use blocking file module to create a file in which we have a block that has IP address name such connection type and password.

So as our Second Inventory is created by running 1st playbook and our os also launched so now we have to play our second playbook that need an inventory that we have and an os that also we have and this playbook will perform a task it will make it as a web-server and start it service

After doing all this we get that our service is started inside the docker that is created by the ansible and also configured by the ansible this is all about tasks so let's start our tasks

1.Our First Playbook file that creates Docker container and takes Docker container info and also creates an inventory for the second Playbook

 cat task14.yml
- hosts: localhost
  vars:
          container_name: centos1
  tasks:
          - docker_container:
                  name: "{{ container_name }}"
                  image: mycentos:ssh1
                  state: started
                  interactive: yes
                  detach: yes
                  tty: yes
                  ports:
                          - "9197:80"
                  restart: yes


          - name: get docker info
            docker_container_info:
                    name: "{{ container_name }}"
            register: x


          - debug:
                  var:  x.container.NetworkSettings.IPAddress
          - blockinfile:
                  path: /root/ansible/ip.txt
                  block: |
                          [docker]
                          {{ x['container']['NetworkSettings']['IPAddress'] }} a                                                                                        nsible_ssh_user=root ansible_ssh_pass=redhat ansible_connection=ssh

this is our playbook first

NOw let's see our Inventory file for the second os and also that is our second os is running or not

Our inventory file is

 cat ip.txt


# BEGIN ANSIBLE MANAGED BLOCK
[docker]
172.17.0.2 ansible_ssh_user=root ansible_ssh_pass=redhat ansible_connection=ssh
# END ANSIBLE MANAGED BLOCK

This is our inventory file that is created by Playbook 1

Our docker container running proof

No alt text provided for this image

it means our First playbook running successfully without any error and so all its tasks

NOw we can see our ansible config file that has inventory for seconf os

 cat ansible.cfg
[defaults]
inventory = /root/ansible/ip.txt
host_key_checking=false
remote_user=root
roles_path=/root/ansible/role/


[privilege_escalation]
become=true
become_method=sudo
become_user=root
become_ask_pass=false

After this let's see our and playbook that will configure httpd on our second os

 cat web.yml
- hosts: docker
  tasks:
          - package:
                  name: httpd
                  state: present
          - copy:
                  src: /root/index.html
                  dest: /var/www/html/


          - name: strt service
            command: /usr/sbin/httpd

When we run this it will configure our Docker as an Httpd server or we can say the website

Let's see is it running or not in two ways checking with netstat -help and via curl

Cirl--

No alt text provided for this image

netstat---

No alt text provided for this image

It means our setup is working fine We can successfully create a docker container via ansible and also configured it as an HTTPd webserver

OP of successfully running of Playbook 1 is

No alt text provided for this image
No alt text provided for this image

O/p of ip.txt and

No alt text provided for this image

O/p of playbook2

No alt text provided for this image
No alt text provided for this image

Confirmation of docker launched and configured successfully is here

No alt text provided for this image

Thanks for reading

HAve A Nice Day











要查看或添加评论,请登录

Gaurav Rathi的更多文章

  • GUI Application inside Docker

    GUI Application inside Docker

    Docker containers run as a process under the main operating system, you can run multiple containers on a single…

  • Industry Use-Cases of Jenkins

    Industry Use-Cases of Jenkins

    In this article, we are going to learn about the DevOps tool and the name of that tool is Jenkins This is the main tool…

  • Research for Industry Use-Cases of Openshift

    Research for Industry Use-Cases of Openshift

    In this article we are going to learn about OpenShift and how it works and what is the need for these tools in the…

  • NETFLIX-AWS CASE STUDY

    NETFLIX-AWS CASE STUDY

    In this blog, we are going to learn how Netflix uses AWS cloud to run its business. AWS provides resources to Netflix…

  • Industry Use-Case of Neural Networks(NN)

    Industry Use-Case of Neural Networks(NN)

    What is a Neural Network? Neural networks can be taught to perform complex tasks and do not require programming as…

  • AKS-Azure Kubernetes Service

    AKS-Azure Kubernetes Service

    AKS is a good example of INFRASTRUCTURE as a Service and PLATFORM as a Service. Here as we know Azure is a public…

  • Summary of Expert Session Delivered on Kubernetes | Container | Openshift

    Summary of Expert Session Delivered on Kubernetes | Container | Openshift

    Hello Connections, “Expert session on Industry use cases of Kubernetes/OpenShift ” was one of the great sessions. Which…

  • Git and GitHub Workshop

    Git and GitHub Workshop

    What is GIT? Git is a distributed version control system for tracking changes in any set of files, originally designed…

  • ARTH - Task 14.3 ??????

    ARTH - Task 14.3 ??????

    Task Description: Create an Ansible Playbook which Dynamically Loads Variable Filename same as OS_Name and just by…

  • ARTH - Task 17 ??????

    ARTH - Task 17 ??????

    Task Description?? ?? Create your own Chat Servers, and establish a network to transfer data using Socket Programing by…

社区洞察

其他会员也浏览了