By continuing to navigate on this website, you accept the use of cookies to serve you more relevant services & content.
For more information and to change the setting of cookies on your computer, please read our Cookie Policy.

Ansible Galaxy Introduction.

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:

Run: ansible-galaxy init my_playbook

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.
In vars/main.yml

---
# vars file for mysql_server
mysql_server_password:  mysql_server_password

Now create a task which sets password and installs mysql.
In tasks/main.yml:

---
# tasks file for mysql_server

- name: Setting MySQL root password before installing
  debconf: "name='mysql-server' question='mysql-server/root_password' value='{{mysql_server_password | quote}}' vtype='password'"

- name: Confirm MySQL root password before installing
  debconf: "name='mysql-server' question='mysql-server/root_password_again' value='{{mysql_server_password | quote}}' vtype='password'"

- name: Install MySQL
  apt: "package='{{ item }}' state=present force=yes"
  when: ansible_os_family == 'Debian'
  with_items:
    - mysql-server
    - libmysqlclient-dev

 

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)

---
- hosts: my_server
  remote_user: root
  roles:
    - { role: my_playbook }

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.

    Posted On
  • 16 June 2015
  • By
  • Micropyramid

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Configure SSL with LetsEncrypt and nginx

Configuring SSL is beneficial not only for security purpose but also for SEO too.
Linuxsoftware foundation's initiated a program called Let’s Encrypt to give ssl ...

Continue Reading...
Automate Django Deployments with fabfile

Fabric is a Python library and command-line tool with the ability to execute commands on a remote server. It is designed to use SSH to ...

Continue Reading...
TMUX - Sharing terminal between Users

More Often you wouldve come across sharing screens with applications like Teamviewer, Windows Remote Desktop Connection or remmina (if you're a linux user). But if ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties