Get up and running with Ansible in 10 minutes or less! This should not be seen as a comprehensive guide but rather a quick start to get you running Ansible. For this guide we will be running against an Ubuntu system, however the steps are very similar for RHEL as well. You do need to have another server’s ip address or you can use your own local host.
First, we should install the proper packages through a Personal Package Archive. To do this run
- sudo apt-get install -y software-properties-common ssh
- sudo apt-add-repository –yes –update ppa:ansible/ansible
- sudo apt-get install -y ansible
Check the install with ansible –version and you should see the version and below it a config file is listed with the path /etc/ansible/ansible.cfg. You will want to sudo vim /etc/ansible/ansible.cfg. While in vim, uncomment the lines inventory and sudo_user as pictured below then save the changes.
Ansible is run against nodes that we identify in the hosts file. To set up a basic hosts file first we will save a copy of the sample hosts file and then create our own.
- sudo mv /etc/ansible/hosts /etc/ansible/hosts.original
- vim /etc/ansible/hosts
Inside this file we need to add the ip address of the client you want to run ansible on. You can also run this against your own local host.
Now let’s make our playbook. Run sudo vim /etc/ansible/playbook.yml and copy the below into the file. Save and exit.
We now need to create a roles directory and a directory for our basic job. Run sudo mkdir -p /roles/basic/tasks and then sudo vim /etc/ansible/roles/basic/tasks/main.yml and copy the following simple command.
To run the command simple use ansible-playbook -u [user on client] /etc/ansible/playbook.yml. You should get confirmation that it has successfully run and you can check to make sure /tmp/ansible exists on your client. As you develop with Ansible further, you should not be working in the /etc directory.