Skip to main content

Ansible

Ansible

------------------------------------------------------------------------------------------------------------------------------------------------

What is Ansible?

Ansible is an agentless automation system developer by RedHat, designed for deploying changes across any number of machines.

------------------------------------------------------------------------------------------------------------------------------------------------

Installing Ansible (Management Server)

apt install ansible

------------------------------------------------------------------------------------------------------------------------------------------------

Configuring Ansible w/ Basic Example

To use Ansible, you'll need to create a YAML file for Ansible to read from:

vim inventory.yaml

Basic YAML file example:

all:  # Define a section named "all"
  hosts:  # Define a section for target hosts within "all"
    server_name: ansible_host: IP_IP_IP_IP  # Host entry with label "server_name" (replace IP with actual server IP)
    server2_name: ansible_host: IP_IP_IP_IP  # Another host entry with label "server2_name" (replace IP with actual server2 IP)
  vars:  # Define a section for variables
    ansible_connection: ssh  # Specify SSH connection type
    ansible_ssh_user: ssh_username  # Define username for SSH authentication
    ansible_ssh_private_key_file: /path/to/key/on/ansible/server  # Define path to private key file for SSH authentication on Ansible 

 This configuration doesn't make any automated changes to hosts, instead, it's just defining what the hosts are, and how to authenticate to them.

Using this configuration, we can run the command below to ping all hosts in the YAML file:

ansible -i inventory.yaml all -m ping

The -i flag, also written as --inventory, is used with the ansible command to specify the inventory file that defines the target hosts for your Ansible playbooks.

-m ping: This flag specifies the module to be executed on the target hosts. In this case, -m ping (or --module ping) tells Ansible to run the "ping" module.

------------------------------------------------------------------------------------------------------------------------------------------------