Would you like to learn how to create an Ansible playbook for Ubuntu LInux? In this tutorial, we are going to show Ansible playbook examples to use on a computer running Ubuntu Linux.
• Ubuntu 18.04
• Ubuntu 19.04
• Ansible 2.8.6
Hardware List:
The following section presents the list of equipment used to create this Ansible tutorial.
Every piece of hardware listed above can be found at Amazon website.
Ansible Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Ansible.
Ansible Playbook Example – Install a Package using Apt-get
This Ansible playbook example named install-apt.yml will install the Ntpdate and the Nmap packages on All Ansible nodes.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will connect to all nodes and install the required packages.
Ansible Playbook Example – Running a Shell Command
This Ansible playbook example named linux-echo.yml will execute a command on the Linux shell.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will connect to all nodes and install the required packages.
Ansible Playbook Example – Running a Raw Command
This Ansible playbook example named linux-raw.yml will execute a command on the Linux shell.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will connect to all nodes and install the required packages.
Ansible Playbook Example – Reading a Variable from the Command-line
This Ansible playbook example named linux-scan.yml will install the Nmap package.
It will read the IP addres from the IP_VAR variable and use NMAP to scan this host.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will scan the host techexpert.tips after install the NMAP packge.
This playbook will also display the result on the screen.
Ansible Playbook Example – Update and Upgrade Ubuntu Linux
This Ansible playbook example named ubuntu-upgrade.yml will update the APT-GET database.
This Ansible playbook example will upgrade the ubuntu Linux.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will tell all nodes to update the APT-GET database.
In our example, the Ansible server will tell all nodes to upgrade the Ubuntu Linux pacakges.
Ansible Playbook Example – Parallel Tasks
This Ansible playbook example named ubuntu-parallel.yml will run taks at the same time.
To run this Ansible playbook, use the following command.
In our example, the Ansible server will tell all nodes to run 3 commands in parallel.