Read this in other languages: English, 日本語.
Before you get started, please join us on slack! Click here to join the ansiblenetwork slack. This will allow you to chat with other network automation engineers and get help after the workshops concludes.
Navigate to the f5-workshop
directory.
[student1@ansible ~]$ cd f5-workshop/
[student1@ansible f5-workshop]$
Run the ansible
command with the --version
command to look at what is configured:
[student1@ansible f5-workshop]$ ansible --version
ansible 2.9.14
config file = /home/student1/.ansible.cfg
configured module search path = ['/home/student1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Note: The Ansible version you see might differ from the above output
This command gives you information about the version of Ansible, location of the executable, version of Python, search path for the modules and location of the ansible configuration file
.
Use the cat
command to view the contents of the ansible.cfg
file.
[student1@ansible f5-workshop]$ cat ~/.ansible.cfg
[defaults]
stdout_callback = community.general.yaml
connection = smart
timeout = 60
deprecation_warnings = False
host_key_checking = False
retry_files_enabled = False
inventory = /home/student1/lab_inventory/hosts
[persistent_connection]
connect_timeout = 200
command_timeout = 200
[student1@ansible f5-workshop]$
Note the following parameters within the ansible.cfg
file:
inventory
: shows the location of the ansible inventory being usedThe scope of a play
within a playbook
is limited to the groups of hosts declared within an Ansible inventory. Ansible supports multiple inventory types. An inventory could be a simple flat file with a collection of hosts defined within it or it could be a dynamic script (potentially querying a CMDB backend) that generates a list of devices to run the playbook against.
In this lab you will work with a file based inventory written in the ini format. Use the cat
command to view the contents of your inventory:
[student1@ansible f5-workshop]$ cat ~/lab_inventory/hosts
The output will look as follows with student2 being the respective student workbench:
[all:vars]
ansible_user=student2
ansible_password=ansible
ansible_port=22
[lb]
f5 ansible_host=34.199.128.69 ansible_user=admin private_ip=172.16.26.136 ansible_password=admin
[control]
ansible ansible_host=107.23.192.217 ansible_user=ec2-user private_ip=172.16.207.49
[web]
node1 ansible_host=107.22.141.4 ansible_user=ec2-user private_ip=172.16.170.190
node2 ansible_host=54.146.162.192 ansible_user=ec2-user private_ip=172.16.160.13
Note that the IP addresses will be different in your environment.
In the above output every [ ]
defines a group. For example [web]
is a group that contains the hosts node1
and node2
.
Note: A group called all always exists and contains all groups and hosts defined within an inventory.
We can associate variables to groups and hosts. Host variables are declared/defined on the same line as the host themselves. For example for the host f5
:
f5 ansible_host=34.199.128.69 ansible_user=admin private_ip=172.16.26.136 ansible_password=admin
f5
- The name that Ansible will use. This can but does not have to rely on DNSansible_host
- The IP address that ansible will use, if not configured it will default to DNSansible_user
- The user ansible will use to login to this host, if not configured it will default to the user the playbook is run fromprivate_ip
- This value is not reserved by ansible so it will default to a host variable. This variable can be used by playbooks or ignored completely.ansible_password
- The password ansible will use to login to this host, if not configured it will assume the user the playbook ran from has access to this host through SSH keys.Does the password have to be in plain text? No, Red Hat Ansible Tower can take care of credential management in an easy to use web GUI or a user may use ansible-vault
Go back to the home directory
[student1@ansible f5-workshop]$ cd ~
You have finished this exercise. Click here to return to the lab guide