Skip to content

Latest commit

 

History

History
117 lines (75 loc) · 3.68 KB

Install-Ansible-Basic-Commands.md

File metadata and controls

117 lines (75 loc) · 3.68 KB

LAB: Install Ansible and Test Basic Ansible (Ad-Hoc) Commands

This scenario shows:

  • how to install ansible
  • how to use basic commands

Prerequisite

Steps

  • Install Ansible on all nodes
sudo apt install ansible
  • Create directory and inventory file to put managed nodes' IPs

image

  • Put the managed nodes' IPs into the inventory file

image

  • Ping all nodes with ansible
ansible all -i inventory -m ping

image

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

image

image

  • Using config file (ansible.cfg), we can use short commands

image

  • List all hosts
ansible all --list-hosts

image

  • Gather all nodes' information (all resources' information: cpu, ip, ssd, etc.) from all hosts
# -m parameter means ansible module
ansible all -m gather_facts

image

  • 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

image

  • 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

image image image

  • 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

image

  • 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

image