• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

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
{{postValue.id}}

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.

Tags:
keeljohnston
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is Playbook?

A

Ansible Playbooks offer a repeatable, re-usable, simple configuration management and multi-machine deployment system, one that is well suited to deploying complex applications. If you need to execute a task with Ansible more than once, write a playbook and put it under source control. Then you can use the playbook to push out new configuration or confirm the configuration of remote systems.

Q

What should be included in a playbook?

A

A Company Playbook is a guide to your company – basically, what your company does and why. It usually includes a company overview, company history, what you do for your customers, how you engage with your customers, your mission and value statements and how you operate.

Q

In which order are tasks in a playbook executed?

A

Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.

Q

What is the purpose of a playbook?

A

A playbook provides a repository of information outlining an organization's clarity. Clarity is initially established by answering the six critical questions in a concise, actionable way, so that they can be used in decision making, communication and planning.

Q

What is the difference between runbook and playbook?

A

While runbooks define individual processes, playbooks deal with overarching responses to larger issues or events and may incorporate multiple runbooks and personnel within them.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Elijah ?
Remote Desktop Connection Has Stopped Working

When accessing my remote machine server using remote desktop on a windows machine I am getting this error

forum (1)

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.