How to create Ansible Inclusion In Ansible on Centos7
To create Ansible Inclusion In Ansible on Centos7
Introduction:
Ansible is an agentless computerization tool that can install on a control node. Using the control node, Ansible runs machines and other devices remotely. (by default, over the SSH protocol.
Steps:
Check the Os version by using below command:
[root@linuxhelp ~]# lsb_release -d
Description: CentOS Linux release 7.6.1810 (Core)
List the directory:
[root@linuxhelp ~]# ls
anaconda-ks.cfg ansible_inclusion hello.txt original-ks.cfg
Switch to ansible inclusion directory:
[root@linuxhelp ~]# cd ansible_inclusion/
List the directory:
[root@linuxhelp ansible_inclusion]# ls
ansible.cfg hosts setup.yml tasks.yml
Open the setup.yml file:
[root@linuxhelp ansible_inclusion]# vi setup.yml
Open the tasks.yml file:
[root@linuxhelp ansible_inclusion]# vi tasks.yml
[root@linuxhelp ansible_inclusion]# ansible-playbook setup.yml --syntax-check
playbook: setup.yml
Run the setup.yml file:
[root@linuxhelp ansible_inclusion]# ansible-playbook setup.yml
PLAY [Deploying service] **************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
ok: [client]
TASK [install the samba package] ******************************************************************************************************
ok: [client]
TASK [start the smb package] **********************************************************************************************************
changed: [client]
TASK [debugs the tasks] ***************************************************************************************************************
ok: [client] => {
"msg": "output"
}
PLAY RECAP ****************************************************************************************************************************
client : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0
Open the packages.yml file:
[root@linuxhelp ansible_inclusion]# vi packages.yml
[root@linuxhelp ansible_inclusion]# vi installpkg.yml
[root@linuxhelp ansible_inclusion]# ansible-playbook installpkg.yml --syntax-check
playbook: installpkg.yml
Run the installpkg file:
[root@linuxhelp ansible_inclusion]# ansible-playbook installpkg.yml
PLAY [install packages] ***************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************
ok: [client]
TASK [include packages] ***************************************************************************************************************
ok: [client]
TASK [install httpd] ******************************************************************************************************************
ok: [client]
PLAY RECAP ****************************************************************************************************************************
client : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
with this method creation of Ansible Inclusion comes to an end.
Q
Does Ansible use Python?
A
While you can write Ansible modules in any language, most Ansible modules are written in Python, including the ones central to letting Ansible work. By default, Ansible assumes it can find a /usr/bin/python on your remote system that is either Python2, version 2.6 or higher or Python3, 3.5 or higher.
Q
How do I see all the inventory variables defined for my host?
A
By running the following command, you can see inventory variables for a host:
#ansible-inventory --list --yaml
#ansible-inventory --list --yaml
Q
How do I speed up run of ansible for servers from cloud providers?
A
Don’t try to manage a fleet of machines of a cloud provider from your laptop. Rather connect to a management node inside this cloud provider first and run Ansible from there.
Q
How do I copy files recursively onto a target host?
A
The “copy” module has a recursive parameter, though if you want to do something more efficient for a large number of files, take a look at the “synchronize” module instead, which wraps rsync. See the module index for info on both of these modules.
Q
How do I see a list of all of the ansible_ variables?
A
Ansible by default gathers “facts” about the machines under management, and these facts can be accessed in Playbooks and in templates. To see a list of all of the facts that are available about a machine, you can run the “setup” module as an ad-hoc action:
#ansible -m setup hostname
#ansible -m setup hostname