Ansible Step1

I'm following youtube channel https://www.youtube.com/watch?v=KuTPh4GUGdc


How to install Ansible in RHEL? 

yum install ansible  or

pip3 install ansible


Checking configuration path

[root@ip-172-31-77-201 ec2-user]# ansible-config --version

ansible-config 2.9.12

  config file = None

  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible

  executable location = /usr/local/bin/ansible-config

  python version = 3.8.0 (default, Mar  9 2020, 18:02:46) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

[root@ip-172-31-77-201 ec2-user]#


List configurations 

ansible-config list


How ansible uses config files if you have more than one config files?

eg: 

1st preference goes to ANSIBLE_CONFIG variable

export ANSIBLE_CONFIG=/tmp/ansible.cfg

2nd preference goes to present working directory, it could be anything

/opt/myscript/ansible.cfg 


3rd preference goes to current home directory as a hidden file

.ansible.cfg

In case ansible.cfg is not found in above all 3 locations then finally it will use the default location config file which is located in /etc/ansible/ansible.cfg


https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings


How to know which config file is being used?

ansible -i inventory test -m shell -a uptime -v

No config file found; using defaults

Creating inventory file

create server inventory file with all server names which you want to manage certain tasks

eg:

mongodb01.abc.com

mongodb02.abc.com

mongodb03.abc.com


or you can create groups within the inventory 

eg:

db-servers

mongodb01.abc.com

mongodb02.abc.com

mongodb03.abc.com

web-servers

apache01.abc.com

apache02.abc.com

apache03.abc.com


How to run the ansible ad-hoc tasks for the entire inventory file?

ansible -i /opt/scripts/inventory  -m shell  -a "uptime"


How to run the ansible ad-hoc tasks for the only one group of servers in the inventory file?

ansible -i /opt/scripts/inventory db-servers -m -a "uptime"


 

Comments

Popular posts from this blog

Ansible step3 (Play books)

Ansible 4: Playbooks with notify & Handlers