How to create Ansible Playbook on Centos7
- 01:39 lsb_release -d
- 01:50 vi /etc/ansible/hosts
- 02:03 mkdir playbook
- 02:06 cd playbook/
- 02:14 vi test_playbook.yaml
- 03:04 ansible-playbook test_playbook.yaml --syntax-check
- 03:28 ansible-playbook test_playbook.yaml
- 03:54 ansible-playbook test_playbook.yaml -v
- 04:07 ansible-playbook test_playbook.yaml -vv
- 04:24 ansible-playbook test_playbook.yaml -vvv
To create Ansible Playbook on Centos7
Introduction:
Ansible Playbook is a blueprint of automation tasks that allows a repeatable, reusable, easy configuration management and multi-machine deployment system, one that is fully adapted to expanding complex applications. If you need to execute a task with Ansible more than once, write a playbook and installed it below source control. Then we can use the playbook to push out new configurations or confirm the configuration of remote systems.
Procedure:
Check the OS version by using the following command:
[root@linuxhelp ~]# lsb_release -d
Description: CentOS Linux release 7.6.1810 (Core)
Open the hosts file and add the client host Ip:
[root@linuxhelp ~]# vi /etc/ansible/hosts
Create a directory for Playbook:
[root@linuxhelp ~]# mkdir playbook
Switch to playbook directory:
[root@linuxhelp ~]# cd playbook/
Create a yaml file for playbook:
[root@linuxhelp playbook]# vi test_playbook.yaml
Check the syntax of the yaml file by using following command:
[root@linuxhelp playbook]# ansible-playbook test_playbook.yaml --syntax-check
playbook: test_playbook.yaml
Execute the playbook file by using following command:
[root@linuxhelp playbook]# ansible-playbook test_playbook.yaml
PLAY [Test playbook] ***********************************************************
TASK [Gathering Facts] *********************************************************
ok: [Client]
TASK [Get hostname] ************************************************************
changed: [Client]
PLAY RECAP *********************************************************************
Client : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Once completed execute the following command to see the details of the executed file:
[root@linuxhelp playbook]# ansible-playbook test_playbook.yaml -v
Using /etc/ansible/ansible.cfg as config file
PLAY [Test playbook] ***********************************************************
TASK [Gathering Facts] *********************************************************
ok: [Client]
TASK [Get hostname] ************************************************************
changed: [Client] => {"changed": true, "cmd": ["hostname"], "delta": "0:00:00.007324", "end": "2021-03-30 15:32:44.308257", "rc": 0, "start": "2021-03-30 15:32:44.300933", "stderr": "", "stderr_lines": [], "stdout": "localhost.localdomain", "stdout_lines": ["localhost.localdomain"]}
PLAY RECAP *********************************************************************
Client : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Add one more “v” at the end of the command to see more details:
[root@linuxhelp playbook]# ansible-playbook test_playbook.yaml -vv
ansible-playbook 2.9.18
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
.
.
.
.
Add one more “v” at the end of the command to see more details:
[root@linuxhelp playbook]# ansible-playbook test_playbook.yaml -vvv
ansible-playbook 2.9.18
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
.
.
.
.
With this method creation of Ansible playbook on Centos 7 comes to an end.
Comments ( 0 )
No comments available