2025-11-18 13:42:33 +00:00
2025-11-20 13:11:37 +01:00
2025-11-20 13:01:18 +01:00
2025-05-30 09:53:45 +02:00
2025-11-17 09:45:08 +01:00
2025-11-18 10:38:05 +01:00

Agile611

Agile611 Ansible Training

This repository contains the code examples from the configuration management tools Ansible. It uses Vagrant to demonstrate these tools in practice.

Requirements

  • git: Necessary to clone the code.
  • Vagrant: This repository uses a Vagrant box based on Ubuntu, and APT will be used to install Ansible.
  • Virtualbox: It is the engine for virtualize the environment.

Example Code

Clone the repository:

git clone https://www.github.com/agile611/startusingansible.git

Initial Configuration

Start the environment, requiring four Ubuntu boxes (Ansible, Loadbalancer, Database, Webserver):

vagrant up
vagrant ssh ansible

Create an SSH key to connect the VMs without password:

ssh-keygen
cat /home/vagrant/.ssh/id_rsa.pub

Copy the public key to the VMs and set up the authorized keys:

vagrant@ansible$ ssh-copy-id vagrant@192.168.11.20
vagrant@ansible$ ssh-copy-id vagrant@192.168.11.30
vagrant@ansible$ ssh-copy-id vagrant@192.168.11.40

Verify SSH connection:

ssh vagrant@192.168.11.20

If any password is asked, the user is vagrant and the password is vagrant.

Important Note

The configuration file priority order is as follows:

  1. ANSIBLE_CONFIG (environment variable)
  2. ansible.cfg (current folder)
  3. ~/.ansible.cfg (user home)
  4. /etc/ansible/ansible.cfg (general file)

Test the Environment

Set up Ansible Inventory on the Ansible box:

mkdir example_ansible
mkdir example_ansible/hosts
nano example_ansible/hosts/all

Add the following lines to hosts/all:

[all:vars]
ansible_python_interpreter=/usr/bin/python3.12
[database]
192.168.11.20
[loadbalancer]
192.168.11.30
[webserver]
192.168.11.40

Check if everything works:

cd example_ansible
ansible -i hosts -u root -m ping all

Initial Configuration and First YAML File

Create the file request.yml:

---
- hosts: webserver
  tasks:
    - name: What system are you?
      command: uname -a
      register: info
    - name: print var
      debug:
        var: info
    - name: print field
      debug:
        var: info.stdout
    - name: What your name?
      command: hostname
      register: info
    - name: Give me your name
      debug:
        var: info.stdout

Execute the playbook:

ansible-playbook -i hosts/all -u root request.yml --list-hosts --list-tasks
ansible-playbook -i hosts/all -u root request.yml

Additional Examples

Various examples are available in the examples folder, covering different aspects of Ansible usage.

Troubleshooting

If you encounter issues provisioning the box, you can download it directly and add it to Vagrant.

Common networking problems

If you have proxies or VPNs running on your machine, it is possible that Vagrant is not able to provision your environment.

Please check your connectivity before.

Support

This tutorial is released into the public domain by Agile611 under Creative Commons Attribution-NonCommercial 4.0 International.

License: CC BY-NC 4.0

This README file was originally written by Guillem Hernández Sola and is likewise released into the public domain.

Please contact Agile611 for further details.

  • Agile611
  • Laureà Miró 309
  • 08950 Esplugues de Llobregat (Barcelona)
Description
No description provided
Readme 1,004 KiB
Languages
Jinja 86%
Shell 13.3%
PHP 0.7%