root@ip-172-31-87-83:~/daniel# cat git.yaml
- name: Update web servers hosts: web
tasks:
- name: Install git in ubuntu ansible.builtin.apt: name: "git" state: latest
- name: Install wget in ubuntu ansible.builtin.apt: name: "wget"
- name: Copy echo.sh ansible.builtin.copy: src: echo.sh dest: /tmp/echo.sh
- name: Change file ownership, group and permissions ansible.builtin.file: path: /tmp/echo.sh mode: '0755'
- name: Run a script with arguments (free form) ansible.builtin.script: /tmp/echo.sh
- name: Print return information from the previous task ansible.builtin.debug: msg: "The ansible task is completed successfully!"
The playbook result:
root@ip-172-31-87-83:~/daniel# ansible-playbook -i inventory1 git.yaml -u ubuntu --key-file=node.pem -b
PLAY [Update web servers] ******************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************
ok: [54.89.178.94]
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 in ubuntu] ***************************************************************************************************
ok: [54.89.178.94]
TASK [Install wget in ubuntu] **************************************************************************************************
ok: [54.89.178.94]
TASK [Copy echo.sh] ************************************************************************************************************
changed: [54.89.178.94]
TASK [Change file ownership, group and permissions] ****************************************************************************
ok: [54.89.178.94]
TASK [Run a script with arguments (free form)] *********************************************************************************
changed: [54.89.178.94]
TASK [Print return information from the previous task] *************************************************************************
ok: [54.89.178.94] => {
"msg": "The ansible task is completed successfully!"
}
PLAY RECAP *********************************************************************************************************************
10.22.2.2 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
54.89.178.94 : ok=7 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Top comments (0)