Published on

Website Under Construction2

Authors
  • avatar
    Name
    Owais Abbasi
    Twitter

Explanation of the Notes:

  1. Editing the ansible.cfg File:

    • You edited the ansible.cfg file using vim ansible.cfg.
    • Line edited:
      host_key_checking = False
      
    • Purpose: This disables SSH host key checking when Ansible connects to remote machines. By setting host_key_checking to False, Ansible will not ask for confirmation if it has not connected to the target machine before. This makes it easier to manage connections but slightly less secure.
  2. Testing Connection with Ansible Ping:

    • Command used:
      ansible all -m ping
      
    • Purpose: This tests connectivity between the Ansible master and all the nodes listed in the inventory (hosts file). The ping module ensures that the target machines can be reached over SSH and that Python is installed on them.
  3. SSH Key Configuration:

    • SSH Copy Command:
      ssh-copy-id 192.168.1.14
      
    • This command copies your public SSH key to the target machine (192.168.1.14), allowing password-less SSH login.
    • SSH Key Generation:
      ssh-keygen
      
      • Used if no SSH keys exist. You can create a new key pair. When asked to overwrite the existing key, you choose yes if you want to replace the current key.
    • SSH Login without Password:
      ssh aadmin@192.168.1.14
      
      • After copying the SSH key, this command allows password-less login to the node.
  4. Ansible Directory Structure:

    • Example directory structure:
      .
      |-- ansible.cfg
      |-- hosts
      `-- roles
      
    • ansible.cfg: Configuration file for Ansible.
    • hosts: Inventory file that lists all the nodes you want to manage with Ansible.
    • roles: A directory used to organize playbooks into reusable roles (collections of tasks, handlers, variables, and other components).
  5. Checking Ansible Version and Config File Location:

    • Command used:

      ansible --version
      
    • Displays the version of Ansible and the current configuration file (ansible.cfg) being used. The configuration file can be found in different locations, such as:

      1. The ANSIBLE_CONFIG environment variable (if set).
      2. The ansible.cfg file in the current directory.
      3. The ansible.cfg file in the home directory.
      4. The default /etc/ansible/ansible.cfg.
    • Changing Configuration Path:

      export ANSIBLE_CONFIG=/home/aadmin/ansible
      
      • Changes the configuration file being used by Ansible to /home/aadmin/ansible/ansible.cfg via the environment variable.
  6. Using the Inventory File and Ping:

    • Inventory Location:

      inventory = /home/aadmin/ansible/hosts
      
      • This specifies the location of the inventory file that contains the IPs or hostnames of the nodes.
    • Ping using Inventory:

      ansible all -i /home/aadmin/inv -m ping
      
      • You manually specify the inventory file to check the connection to all hosts listed.
  7. Testing Connections to Specific IPs:

    • Ping specific hosts:

      ansible 192.168.1.14 -m ping
      
      • This command checks the connection to a single host (192.168.1.14) using Ansible.
      ansible 192.168.1.14:192.168.1.15 -m ping
      
      • Checks multiple hosts separated by colons (:).
  8. Managing Groups of Hosts:

    • Inventory Groups:

      [docker]
      192.168.1.14
      
      [was]
      192.168.1.15
      192.168.1.16
      192.168.1.17
      
      • The hosts file defines groups of hosts. You can group hosts by categories like docker and was.
    • Ping Specific Groups:

      ansible docker -m ping
      ansible was -m ping
      
      • These commands ping all the nodes in the docker and was groups, respectively.
  9. Common Issues:

    • Some nodes, like 192.168.1.15, 192.168.1.16, and 192.168.1.17, are unreachable. This is typically caused by issues such as:
      • SSH keys not being copied properly.
      • SSH service not running or misconfigured on the nodes.
      • Firewall rules preventing the connection.

Commands on Master and Node Machines:

  1. Master Machine Commands:

    • Edit ansible.cfg:
      vim /etc/ansible/ansible.cfg
      
    • Generate SSH Keys (if needed):
      ssh-keygen
      
    • Copy SSH Key to Nodes:
      ssh-copy-id 192.168.1.14
      ssh-copy-id 192.168.1.15
      ssh-copy-id 192.168.1.16
      ssh-copy-id 192.168.1.17
      
    • Ping Nodes via Ansible:
      ansible all -m ping
      ansible docker -m ping
      ansible was -m ping
      
  2. Node Machine Commands:

    • On each node, ensure SSH is configured correctly:
      • Check SSH service is running:
        sudo systemctl status ssh
        
      • Ensure SSH port (22) is open in the firewall.
      • Verify SSH keys have been copied correctly:
        ls ~/.ssh/authorized_keys
        

These commands will help you configure and troubleshoot Ansible and SSH connectivity between the master and nodes.---

AI Driven Secure Cloud DevOps - Your source for everything DevOps, cloud, and security.