In the previous article of this series, we wrote about the server configuration management tools for the cloud servers. We also said that, Ansible is easiest. Here is How to Get Started With Ansible. Installation is on Local Computer to log into a Server From Installing Package or Restart Services. We are taking that you are using OS X or GNU/Linux. In case you are using Windows PC, you can follow the GNU/Linux way or read our previously published guide to create a unix environment on Windows PC.
Get Started With Ansible : Before Installation
You possibly know that, some of the users use Vagrant with Ansible. Why people uses Vagrant with Ansible has an easy answer – to get a GNU/Linux server to test. We wrote about how to use Vagrant for OctoPress on another guide. This guide is Ansible without Vagrant i.e. you are executing the commands on a spare GNU/Linux server. After practicing few times, you can run the commands on production server. For the production servers, we have guide to use Git to take backup of the installed package’s configuration files. To check what packages are installed on your production server follow this guide. For OS X, we use iTerm2, Homebrew in this standard way.
Get Started With Ansible : Installation
For OS X with Homebrew, to get started with Ansible installation, practically one command is needed :
---
1 2 | sudo easy_install pip sudo pip install ansible |
For OS X, GNU/Linux other than deb Linux (Debian, Ubuntu etc) to get started with Ansible installation, there is Python :
1 2 | sudo easy_install pip sudo pip install ansible |
For deb Linux (Debian, Ubuntu etc) to get started with Ansible installation, there is apt :
1 2 3 4 | sudo apt-get install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo apt-get update sudo apt-get install ansible |
Ansible is usually inside the /etc/ansible
directory. Ansible uses a file to determine what hosts to work against. That is called inventory file
of Ansible, which is located at /etc/ansible/hosts
with ini
extension. An inventory file is a text file containing a list of host names or IP addresses. For example:
1 2 3 4 5 6 7 8 9 10 11 12 | [example_servers] 100.110.111.200 set_hostname=vm-ex01 # example of setting a host inventory by IP address. [repository_servers] example-repository #example of setting a host by hostname. Requires local lookup in /etc/hosts # or DNS. [webservers] web01 [dbservers] db01 |
Get Started With Ansible : Post Installation Initial Learning
From now, you can use official Ansible docs! Like this is for :
1 | http://docs.ansible.com/ansible/intro_inventory.html |
When we use the Ansible commands, we add flag like –inventory=/path/to/inventory/inventory.ini
. After filling real data, we can ping in this way :
1 | ansible all --inventory-file=inventory.ini --module-name ping -u root |
Where,
--inventory-file=inventory.ini
is our inventory file.--module-name ping
means we will use the ping module.-u root
means we will use username as root.
We can shorten the above common to :
1 | ansible all -i inventory.ini -m ping -u root |
or more shorter (depends on configuration) :
1 | ansible all -m ping |
We can actually add a host to that inventory.ini
in this way :
1 | web ansible_ssh_host=987.654.321.091 |
We used Ansible module. What is this module? A module is a catalog for Ansible to work out of the box. Here is official documentation :
1 | http://docs.ansible.com/ansible/modules_by_category.html |
Yes, you can write your own module too! Here is guide :
1 | http://docs.ansible.com/ansible/developing_modules.html |
We used ping in above example, it is called apt module
.
Ansible Playbooks are YAML files which allow you to organize the configuration and management tasks. Each each of these playbooks contains a list of tasks known as play. Each playbook can be combined with other playbook. That is Roles. Roles are reusable abstractions that contain a collection of features. Ansible has a community for users to share such kind of roles names Ansible Galaxy :
1 | https://galaxy.ansible.com |
We are ending here in this guide as Playbook, Roles, Galaxy need separate guide. You should only ping for now!