In this lab, you will deploy a local Ansible hosts inventory, custom configuration, and supporting variables, to fully and safely automate the process of performing tasks on remote devices in the Lab Network.
Outcomes
You should be able to:
Clone the ansible-generic-project Git repository to create a local directory for your new Ansible project.
Create a hosts inventory file.
Create a directory structure to hold group variables.
Create plain and encrypted group variables files.
Create a Vault password directory and Vault password file outside of your project directory and protect these with appropriate file-system permissions.
Create a local ansible.cfg file to provide customization.
Verify connectivity to managed network devices, omitting the servers.
Commit your work to the Git repository.
Open a terminal window on the workstation VM.
Instructions
Perform the following steps:
Clone the ansible-generic-project Git repository to create a local directory for your new Ansible project.
Use the following URL in the Lab Environment:
http://git.lab.example.com:3000/student/ansible-generic-project.git
Create a hosts inventory file.
Base the hosts inventory file on the contents of Appendix A, Table of Lab Network Hosts and Groups
Create a directory structure to hold group variables.
Create plain and encrypted group files.
Map groups to connection and authentication variables as shown in Appendix B, Connection and Authentication Variables.
Create encrypted vault.yml variable files to hold sensitive data.
Create a Vault password directory and Vault password file outside of your project directory and protect these with appropriate file-system permissions.
Create a local ansible.cfg file to provide local customization.
Use gathering = explicit, for instance, to avoid typing gather_facts: False at the top of every play.
Verify connectivity to managed network devices, omitting the servers.
The verify-access.yml playbook is provided with ansible-generic-project.
Use that playbook to verify access or create your own.
If failing the verification, troubleshoot and resolve the problem.
The show-current-access-vars.yml playbook is also provided with ansible-generic-project.
This might be useful if connection and authentication tests are failing.
Commit your work to the Git repository.
If prompted for credentials, user and password are student and student.
The commands are shown here.
[student@workstation ]$git add -A :/[student@workstation ]$git commit -m "ch7 lab1"[student@workstation ]$git push
Clone the ansible-generic-project Git repository to create a local directory for your new Ansible project.
Use the following URL in the Lab Environment:
http://git.lab.example.com:3000/student/ansible-generic-project.git
[student@workstation ~]$git clone \>http://git.lab.example.com:3000/student/ansible-generic-project.git
Change into the directory created by the git clone command.
[student@workstation ~]$cd ansible-generic-project[student@workstation ansible-generic-project]$
Download the example.com hosts inventory file.
[student@workstation ansible-generic-project]$wget \>http://materials.example.com/full/inventory
Create a directory structure to hold group variables, and create plain and encrypted group variables files.
Create group_vars/ subdirectories for groups with variables listed in Appendix B.
[student@workstation ansible-generic-project]$mkdir -p group_vars/ios[student@workstation ansible-generic-project]$mkdir group_vars/local[student@workstation ansible-generic-project]$mkdir group_vars/network[student@workstation ansible-generic-project]$mkdir group_vars/vyos
Map groups to connection and authentication variables.
[student@workstation ansible-generic-project]$cat group_vars/ios/vars.ymlansible_network_os: ios[student@workstation ansible-generic-project]$cat group_vars/local/vars.ymlansible_network_os: local[student@workstation ansible-generic-project]$cat group_vars/network/vars.ymlansible_connection: network_cli[student@workstation ansible-generic-project]$cat group_vars/vyos/vars.ymlansible_network_os: vyos
Create encrypted vault.yml variables files to hold sensitive data.
Use redhat as the Vault password.
The group_vars/ios/vault.yml file contains "ansible_user: admin" and "ansible_password: student".
[student@workstation ansible-generic-project]$ansible-vault create \>group_vars/ios/vault.ymlNew Vault password:redhatConfirm New Vault password:redhat
The group_vars/vyos/vault.yml file contains "ansible_user: vyos" and "ansible_password: vyos".
[student@workstation ansible-generic-project]$ansible-vault create \>group_vars/vyos/vault.ymlNew Vault password:redhatConfirm New Vault password:redhat
Create a Vault password directory and Vault password file outside of your project directory and protect these with appropriate file-system permissions.
You can skip this step if you already completed it in Guided Exercise 4.3.
[student@workstation ansible-generic-project]$cd ..[student@workstation ~]$mkdir .rhv[student@workstation ~]$chmod 700 .rhv[student@workstation ~]$ls -ld .rhvdrwx------. 2 student student 25 May 29 15:42 .rhv[student@workstation ~]$echo redhat > .rhv/vault-secret[student@workstation ~]$chmod 600 .rhv/vault-secret[student@workstation ~]$ls -l .rhv/vault-secret-rw-------. 1 student student 7 May 29 15:43 .rhv/vault-secret[student@workstation ~]$cd ansible-generic-project
Create a local ansible.cfg file to provide customization.
[student@workstation ansible-generic-project]$cat ansible.cfg[defaults] inventory = inventory host_key_checking = False gathering = explicit vault_password_file = ../.rhv/vault-secret [persistent_connection] command_timeout = 180 connect_timeout = 100 connect_retry_timeout = 100
Verify connectivity to managed network devices, omitting the servers.
The verify-access.yml playbook is provided with the ansible-generic-project Git repo.
Use that playbook to verify access or create your own.
[student@workstation ansible-generic-project]$ansible-playbook verify-access.yml
If failing the verification, troubleshoot and resolve the problem.
The show-current-access-vars.yml playbook is provided with the ansible-generic-project Git repo.
This might be useful if the connection and authentication tests are failing.
Use -l SUBSET to limit the target set to a particular host or group.
In this example, for instance, access variables are viewed for spine01.
[student@workstation ansible-generic-project]$ansible-playbook -l spine01 \>show-current-access-vars.ymlPLAY [a play that exposes the current access vars] *************************** TASK [show the value of key variables] *************************************** ok: [spine01] => { "msg": "host: spine01, con: ssh, nos: vyos, user: vyos, pass: vyos\n" } PLAY RECAP ******************************************************************* spine01 : ok=1 changed=0 unreachable=0 failed=0
Commit your work to the Git repository.
Add a .gitignore file that instructs Git not to store vault.yml files.
[student@workstation ansible-generic-project]$cat .gitignore**/vault.yml
Update the repository.
If prompted the Git credentials are student, password student.
[student@workstation ansible-generic-project]$git add -A :/[student@workstation ansible-generic-project]$git commit -m "ch7 lab 1"[student@workstation ansible-generic-project]$git push