• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial 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
6569

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

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.

Related Tutorials in How to create Ansible Playbook on Centos7

Related Tutorials in How to create Ansible Playbook on Centos7

How To Install AnyDesk on Centos 7
How To Install AnyDesk on Centos 7
Apr 2, 2018
How to install Tiki Wiki CMS Groupware on CentOS 7
How to install Tiki Wiki CMS Groupware on CentOS 7
May 31, 2018
How to install PHP ImageMagick on CentOS 7
How to install PHP ImageMagick on CentOS 7
Nov 4, 2017
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
Jun 4, 2019
How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to enable or disable repositories in CentOS
How to enable or disable repositories in CentOS
Mar 28, 2018
How to install AWStats on CentOS 7
How to install AWStats on CentOS 7
Dec 8, 2017
How to install Apache JMeter in CentOS 7
How to install Apache JMeter in CentOS 7
Mar 24, 2017

Related Forums in How to create Ansible Playbook on Centos7

Related Forums in How to create Ansible Playbook on Centos7

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
CentOS
ceriaimmaculate class=
setfacl : command not found
Jan 3, 2018
CentOS
mason class=
Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)
Nov 20, 2018
CentOS
landon class=
Command to find SNMP Version
May 28, 2018
CentOS
arjitharon class=
cannot start minio service help
Mar 10, 2018
Apache tomcat
AadrikaAnshu class=
Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program
Jun 17, 2019
gitlab
caden class=
Insufficient space in download directory /var/cache/yum/x86_64/6/base/packages
Jul 22, 2019
OpenVAS
frank class=
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dec 20, 2018
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 Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

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.