What you will learn in this TP
- Install Ansible with pip
- Install Ansible with the package manager
- Create an automation account
- Validate the SSH connection
All steps and instructions are shown. Recommended for this lab: guided
Introduction #
Context. Before automating anything, you need a control node and machines that accept it. You prepare the course "env_0" environment.
Prerequisites: the cloned test environment (lab "Test environment setup"), VirtualBox and Vagrant · Estimated time: 40 min
Ansible installed on two machines and a "pong" from every host, as the ansible user with sudo.Setup #
Guided steps, with their solution.
1. Start the environment
Why? The three virtual machines are described in the Vagrantfile: one command creates them identically.
Startenv_0and note the name and IP address of each machine.2. Install with pip
Why? pip gives the latest Ansible version; the virtual environment isolates it from system Python packages.
Onrousseltm-ansible-v02, install Ansible with pip in a virtual environment and check the version.3. Identify the system
Why? The package manager depends on the system family: apt for Debian and Ubuntu, dnf for Red Hat, Rocky and Alma.
Identify the system family and version ofrousseltm-ansible-v01.4. Install with the package manager
Why? The system package is updated with the rest of the machine: it is the simplest choice to maintain.
Install Ansible onrousseltm-ansible-v01with the command suited to its family.5. Create the ansible user
Why? A dedicated automation account is easy to trace and revoke, without touching personal accounts.
On each of the three machines, create theansibleuser and give it passwordless sudo.6. Distribute an SSH key
Why? Ansible connects over SSH: a key avoids passwords and allows unattended automation.
On the control node, generate a key foransible, then add the public key to the ansible accountauthorized_keyson the other machines.7. First ping
Why? The ping module checks the whole chain: SSH, user, Python on the target.
-balso checks sudo.Asansibleon the control node, write an inventory with the noted addresses, then run a ping and a command with privilege escalation.
Validate your work
Check that each goal above is reached and that you get the result described in the introduction.
Difficulty level : ●●○○○ (2/5)
My progress
🧪 Launch the lab environment ↗
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Course Glossary
Ansible
An open source IT automation tool (IaC) enabling configuration management, application deployment, and orchestration, operating agentlessly via SSH.
Recommended Articles
Ansible: the inventory (static, dynamic, groups and variables)
Understand and master the Ansible inventory: INI and YAML files, groups, host and group variables...
Ansible: ad-hoc commands
Run immediate actions on a fleet of servers with ansible: the ping, command, shell, copy, apt, se...
Ansible: structuring your code with roles
Create, organize and reuse Ansible roles: directory layout, defaults, tasks, handlers, templates,...
Ansible: managing security (Vault, SSH, privileges and secrets)
Securing Ansible: Ansible Vault, SSH key authentication, become and sudo, no_log, hardening the c...
Ansible: driving your automations with a graphical interface (AWX, Semaphore, AAP)
Compare and install Ansible's graphical interfaces: AWX, Ansible Automation Platform, Semaphore a...
Ansible: generating dynamic files with Jinja2 and facts
Create dynamic configuration files: Jinja2 templates, variables, facts, filters, loops, condition...
Ansible: going further (testing, quality, CI/CD and performance)
Industrialize Ansible: ansible-lint, yamllint, Molecule, continuous integration, collections, exe...
Ansible best practices: structure, idempotence, security and quality
Ansible best practices: project organization, naming, FQCN, idempotence, modules rather than shel...
Ansible: managing your infrastructure with playbooks (Infrastructure as Code)
Write production playbooks: project structure, plays, handlers, tags, serial strategy, error hand...