Debug School

Ranjith Kumar Ragupathi
Ranjith Kumar Ragupathi

Posted on

Write a Ansible Playbook to install a package called “git”, “wget” and run some bash script.

root@ip-172-31-87-83:~# cat Playbook_script_Ranjith.yml

  • name: Install Git and Wget and Run Bash Script hosts: web become: yes # Run tasks with administrative privileges (sudo)

tasks:
- name: Install Git (for Debian/Ubuntu-based systems)
apt:
name: git
state: present
when: ansible_os_family == 'Debian' or ansible_os_family == 'Ubuntu'

- name: Install Wget (for Debian/Ubuntu-based systems)
  apt:
    name: wget
    state: present
  when: ansible_os_family == 'Debian' or ansible_os_family == 'Ubuntu'
Enter fullscreen mode Exit fullscreen mode

Output:

root@ip-172-31-87-83:~# ansible-playbook -i inventory Playbook_script_Ranjith.yml -u ubuntu --key-file=node.pem -b

PLAY [Install Git and Wget and Run Bash Script] *************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [34.239.106.240]
ok: [54.89.178.94]
fatal: [10.1.1.1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 10.1.1.1 port 22: Connection timed out", "unreachable": true}
fatal: [10.22.2.2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 10.22.2.2 port 22: Connection timed out", "unreachable": true}

TASK [Install Git (for Debian/Ubuntu-based systems)] ********************************************************************************************************
ok: [34.239.106.240]
ok: [54.89.178.94]

TASK [Install Wget (for Debian/Ubuntu-based systems)] *******************************************************************************************************
ok: [34.239.106.240]
ok: [54.89.178.94]

PLAY RECAP **************************************************************************************************************************************************
10.1.1.1 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
10.22.2.2 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
34.239.106.240 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
54.89.178.94 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

root@ip-172-31-87-83:~#

Top comments (0)