Ad-Hoc Commands

Things
1. Roles 
2. Use Playbooks to represent a solution
3. Inventories and Group variables
4. Ansible vault 
5. Modules 

Ansible Commands


ssh-keygen
ssh-copy-id [email protected]

# If the above command didn't work use the below method.

> on controlnode do: 
ssh-keygen 
cat ~/.ssh/id_rsa.pub (copy the value)

# Paste copied public key (control plane) into the authorized_keys in each managed nodes.
cd .ssh (on each workers)
nano authorized_keys 
> Paste keys from controlnode (hence managed nodes know the controlnode IP and public key)

sudo nano /etc/ansible/hosts
############################
[labclients]
10.253.1.18
10.253.1.20

# or just the ip 
10.253.1.18
#Check 
############################
ansible-inventory --list
ansible all -m ping
############################
Run an Ansible ad-hoc command to check the uptime of all remote nodes:
ansible -a "uptime" all

Terminologies in Ansible

  1. Control node or Ansible Server • Server which runs Ansible application
  2. Modules • Module is a command meant to be executed on the client-side • Most of the IT tasks modules are already created and can be found on Ansible website • www.docs.ansible.com → search for module index • Example of modules:
    1. Install http
    2. Enable http service
    3. Start http service
  3. Task • A task is a section that consists of a single procedure to be completed. A task can have multiple modules
  4. Playbook • Automation file with step-by-step execution of multiple tasks
  5. YAML • A Playbook written in YAML language (Yet another markup language)
  6. Inventory • File that has information about remote clients where tasks are executed
  7. Tag • A reference or alias to a specific task
  8. Variable • Variables are like containers that holds the defined value which can be used repetitively
  9. Role • Splitting of Playbook into smaller groups. Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure. After you group your content in roles, you can easily reuse them and share them with other users.

How Ansibel Works?

Untitled

Ansible Vs Puppet and Chef

• Uses simple YAML • Agentless (Only requires SSH access) • Easy installation • Well documented product

• Uses Ruby language which is more difficult to learn, and their support is declining day by day.

• These tools require agents to be installed on clients • The installation process is very complex • Lack of documentation