Ansible contd
Ansible Facts
- Facts are collected by ansible during playbook execution by default.
- This pull information about the node on which execution is happending
- Ansible has a module called setup which can pull facts. Refer Here for facts & Refer Here for setup.
Ansible conditionals
- We can execute a task based on condition using when Refer Here
Ansible variables
- Ansible allows to define variables and use them in playbook.
- First location where we will be adding variables is in inventory
- Refer Here for official docs
Ansible modules
- Refer Here for module index and Refer Here for os package manager modules
- Refer Here for generic os package manager
Lets change the Activity 1 to use conditionals and facts
-
Refer Here for the changes done.
-
Refer Here for the changes done to remove duplicate tasks
-
Using generic modules for package Refer Here for the changes done.
- Lets run this playbook only when os family is Debian or RedHat by using the fail module Refer Here
- Refer Here for the changes done to fail playbook execution on unsupported os families
Exercise
- Ensure you have one ansible control node and one node
- ansible control node:
- ubuntu 22.04
- node:
- ubuntu 20.04
- Configure ansible by ensuring the common user name with sudo permissions is
ansible
Waiting for setup till 9:35 AM
- Write a playbook to install git, tree, net-tools on both node and then adopt to run on ansible control node.
