Ansible Galaxy is the hub of ansible scripts contributed by users.
To follow this article its important that you know about ansible. We have a simple, easy to follow blog about ansible scripting here(https://micropyramid.com/blog/how-to-deploy-django-with-uwsgi-and-nginx-using-ansible-play-book/).
1. Create the skeleton of ansible script:
This command creates the following structure:
my_playbook defaults/ files/ handlers/ meta/ tasks/ templates/ vars/ README.md
defaults: You can declare default configurations or variables.
handlers: Similar to tasks but get invoked by a notifier. Eg: if a task has changed some settings then it will notify this handler to restart a service.
meta: This file contains information about dependencies the current task has to resolve first, author info etc..
tasks: It contains the core logic.
templates: These are jinja2 templates which are simple configuration files.
vars: Contains all the local variables
2. Writing a basic ansible task.
Lets install mysql over Ubuntu server.
First we need to provide password to install mysql. So you can provide password through defaults file or vars file.
Now create a task which sets password and installs mysql.
3. Create a yml file including above task and required configurations.
In test.yml (this file should be in the path of my_playbook directory)
Run: ansible-playbook test.yml
MySQL server will be installed over server.
4. Sharing the above task.
- Push the code to github
- Create an account at ansible galaxy
- add your role
From now on you can simply use "ansible-galaxy pull your_role_name" to access your role.