Ansible Install Package Ansible Level 2 Ansible KodeKloud Engineer Task Success

Ticker

6/recent/ticker-posts

Ansible Install Package Ansible Level 2 Ansible KodeKloud Engineer Task Success

Question: The Nautilus Application development team wanted to test some applications on app servers in Stratos Datacenter. They shared some pre-requisites with the DevOps team, and packages need to be installed on app servers. Since we are already using Ansible for automating such tasks, please perform this task using Ansible as per details mentioned below:

Create an inventory file /home/thor/playbook/inventory on jump host and add all app servers in it.

Create an Ansible playbook /home/thor/playbook/playbook.yml to install httpd package on all  app servers using Ansible yum module.

Make sure user thor should be able to run the playbook on jump host.

Note: Validation will try to run playbook using command ansible-playbook -i inventory playbook.yml so please make sure playbook works this way, without passing any extra arguments.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. All the Best 👍


Solution:  

1Go through the folder mentioned in task and verified the inventory edit user

thor@jumphost ~$  ls -l /home/thor/ansible/

total 4

-rw-r--r-- 1 thor thor 180 Jul 13 07:35 inventory

thor@jumphost ~$ 

thor@jumphost ~$ cd /home/thor/ansible/

thor@jumphost ~$ vi inventory 

thor@jumphost ~/ansible$ cat inventory 

stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n an sible_user=tony

stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@ ansible_user=steve

stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner

thor@jumphost ~/ansible$ 


2.  Create a playbook as per the task 

thor@jumphost ~/playbook$vi  playbook.yml 

thor@jumphost ~/playbook$ cat playbook.yml 

- name: Install Httpd

  hosts: all

  become: yes

  tasks:

    - name: Install latest version of httpd 

      package:

        name:

          - httpd

        state: latest

    - name: Start and enable service httpd

      service:

        name: httpd

        state: started

        enabled: yes 

thor@jumphost ~/playbook$ 

3.Post file saved , run below command to execute the playbook      


thor@jumphost ~/playbook$ ansible-playbook  -i inventory playbook.yml

PLAY [install Httpd] ********************************************************************

TASK [Gathering Facts] ******************************************************************************

ok: [stapp03]

ok: [stapp01]

ok: [stapp02]


TASK [Install latest version of httpd] ***********************************************************

changed: [stapp01]

changed: [stapp02]

changed: [stapp03]

TASK [Start and enable service httpd] ***************************************************************

ok: [stapp01]

ok: [stapp02]

ok: [stapp03]

PLAY RECAP ******************************************************************************************

stapp01                    : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

stapp02                    : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

stapp03                    : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


thor@jumphost ~/playbook$


        

4. validate the task by running the below command

thor@jumphost ~/playbook$ ansible all -m package -a "name=httpd state=present" -i inventory --become

stapp03 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "msg": "Nothing to do",

    "rc": 0,

    "results": []

}

stapp01 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "msg": "Nothing to do",

    "rc": 0,

    "results": []

}

stapp02 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "msg": "Nothing to do",

    "rc": 0,

    "results": []

}

thor@jumphost ~/playbook$ 


5. Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Post a Comment

0 Comments

Latest Posts

Ansible Install Package Ansible Level 2 Ansible KodeKloud Engineer Task Success