Getting Started with Ansible Galaxy
In this tutorial we show you how to use Ansible Galaxy. Ansible Galaxy is a tool that seeks to give visibility to one of Ansible’s most exciting features: reusable roles for server configuration or the installation of applications. Many users share roles on Ansible Galaxy.
Ansible roles consist of playbooks that group multiple tasks into one container. They allow the performance of automation tasks with clean directory structures.
You may need certain IAM permissions to carry out some actions described on this page. This means:
To use roles in Ansible playbooks, you must first download them.
Install Apache, MySQL and PHP.ansible-galaxy install geerlingguy.apache geerlingguy.mysql geerlingguy.phpNote:
In this example we use
geerlinguy’s role, which is a software developer involved in many open source development communities. The latest version will be dowloaded if you do not specify which one you want to download. Add the version after the role name to specify a version. Example:
If you want to use other roles, check out geerlinguy’s Ansible profile.
Create an Ansible playbook named
lamp.ymlwith the following contents:---- hosts: allroles:- geerlingguy.mysql- geerlingguy.apache- geerlingguy.php
Run the playbook against a hostansible-playbook lamp.yml
The LAMP server is now created.
Apache Solr is a fast open-source Java search server. Solr enables you to easily create search engines that search websites, databases and files.
For more information on Solr, refer to the Solr official documentation.
- Install Java, tomcat6, Solr with an ansible-galaxy command. We will use the role from
geerlinguywho is a software developer involved in many open source development communities. Check geerlinguy for many other roles.ansible-galaxy install geerlingguy.java geerlingguy.tomcat6 geerlingguy.solr
- Create a playbook named
solr.ymlwith the following contents:---- hosts: allroles:- geerlingguy.java- geerlingguy.tomcat6- geerlingguy.solr
- Run the playbook against a host
The Solr server is now created.
Some other helpful
ansible-galaxy commands are:
ansible-galaxy listdisplays a list of installed roles, with version numbers
ansible-galaxy remove [role]removes an installed role
ansible-galaxy initcan be used to create a role template suitable for submission to Ansible Galaxy
Additionally, you can configure the default path where Ansible roles are downloaded by editing your
ansible.cfg configuration file (normally located in
/etc/ansible/ansible.cfg) and setting a roles_path in the [defaults] section.
For more information on Galaxy commands, refer to the official documentation.