Learn by doing. NoM Ansible Training #1
1. Install Ansible
On Ubuntu:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
Reference (other methods and operating system)
https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
2. What is Idempotence?
# Try the following commands
mkdir testdirectory1
mkdir testdirectory1
# What happens?
# Clean Up
rm -r testdirectory1
# Try a slightly different command
mkdir -p testdirectory1
mkdir -p testdirectory1
# What happens?
3. Do it via Ansible
Create a file called playbook.yaml
with the following contents.
Note that we are creating two different directories.
- name: test-playbook
hosts: localhost
tasks:
- name: Creates directory 1
ansible.builtin.file:
path: testdirectory1
state: directory
- name: Creates directory 2
ansible.builtin.file:
path: testdirectory2
state: directory
Then run the following command twice.
ansible-playbook playbook.yaml
ansible-playbook playbook.yaml
# What happens?
# Delete only one
rm -r testdirectory1
# Again
ansible-playbook playbook.yaml
Reference:
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html