This scenario shows:
- how to install ansible
- how to use basic commands
- You should have a look following lab, nodes that are created in that LAB, are using in ansible commands
- Install Ansible on all nodes
sudo apt install ansible
- Create directory and inventory file to put managed nodes' IPs
- Put the managed nodes' IPs into the inventory file
- Ping all nodes with ansible
ansible all -i inventory -m ping
NOTE: If you use secure private SSH keys on each nodes (copied these keys on each nodes), it should be used "ansible all --key-file ~/.ssh -i inventory -m ping"
- Create config file (ansible.cfg)
touch ansible.cfg
# copy followings:
[defaults]
inventory = inventory
# private_key_file = ~/.ssh/ansible
- Using config file (ansible.cfg), we can use short commands
- List all hosts
ansible all --list-hosts
- Gather all nodes' information (all resources' information: cpu, ip, ssd, etc.) from all hosts
# -m parameter means ansible module
ansible all -m gather_facts
- Gather information from specific node
ansible all -m gather_facts --limit 172.26.215.23
- Run "sudo apt update" for all nodes using ansible
- As it is seen in the printscreen, it does not work.
ansible all -m apt -a update_cache=true
- The reason why "sudo apt update" does not work is to enter "sudo" password for all nodes.
- For now, we are assigning same password for all nodes (node1, node2). Later, it will be shown for different passwords.
sudo passwd ubuntu
- Run "sudo apt update" for all nodes using "BECOME PASS", enter the common password when it asks
ansible all -m apt -a update_cache=true --become --ask-become-pass
- Install specific package "sudo apt get snapd"
ansible all -m apt -a name=snapd --become --ask-become-pass
# latest version
ansible all -m apt -a "name=snapd state=latest" --become --ask-become-pass