Ad-Hoc Commands
- Importatnt concepts to learn:
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
- Control node or Ansible Server
• Server which runs Ansible application
- 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:
- Install http
- Enable http service
- Start http service
- Task
• A task is a section that consists of a single procedure to be completed. A task can have
multiple modules
- Playbook
• Automation file with step-by-step execution of multiple tasks
- YAML
• A Playbook written in YAML language (Yet another markup language)
- Inventory
• File that has information about remote clients where tasks are executed
- Tag
• A reference or alias to a specific task
- Variable
• Variables are like containers that holds the defined value which can be used repetitively
- 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](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7a766177-0e89-438e-85b1-e060461877ab/Untitled.png)
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