GithubHelp home page GithubHelp logo

ansible-starter's Introduction

Ansible Starter Kit

This Ansible Playbooks Starter Kit is a collection of ideas and best practices in organizing and using Ansible. I used Ansible for several projects in many companies and stumbled across different approaches to organize all the mess. This is the essence of my learnings so I won't forget it.

This repo only includes two roles for demonstration purposes. I maintain a repository with my essential roles in another repository. (That can be includes in ansible.cfg.)

Installation

You need a working Python installation and pip installed.

pip install -r requirements.txt

Usage

I add every host to at least one group in ansible_hosts. This can be cluster groups (e.g. consul-servers) or groups for a special purpose (e.g. streaming-servers).

Every role has a group too (e.g. role apache to install Apache on a server). So I can add hosts or groups to a group that belong to a specific role to execute the tasks of this role on this hosts.

Assume a group webservers with 4 hosts in ansible_hosts and a group workers:

[webservers]
web1 ansible_host=web1.servers.local primary_ipv4=192.168.1.1
web2 ansible_host=web2.servers.local primary_ipv4=192.168.1.2
web3 ansible_host=web3.servers.local primary_ipv4=192.168.1.3
web4 ansible_host=web4.servers.local primary_ipv4=192.168.1.4

[workers]
worker1 ansible_host=worker1.servers.local primary_ipv4=192.168.2.1

(I use short names like web1 and explicitly set a long name with ansible_host. The variable primary_ipv4 is no official Ansible variable like ansible_host. But it's often a good choice to see the IP address of a host at frist sight and I use it in some roles.)

If I need to install Aapche on all webservers and worker hosts I add them to the apache group:

[apache:children]
webservers
workers

In site.yaml every role gets an entry like this:

- name: Install Apache
  hosts: apache
  become: yes
  gather_facts: yes
  strategy: free
  roles:
  - { role: apache, tags: ['apache'] }

After that it's easy to work on a specific host or group:

ansible-playbook site.yaml --limit webservers

Or execute a specific tag like apache:

ansible-playbook site.yaml --tags "apache"

If you need to set variables for groups or hosts create a folder with the name of the group in group_vars or of the host in host_vars. Put YAML files with your settings in these folders.

ansible-starter's People

Contributors

pteich avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.