Giter Site home page Giter Site logo

ansible-notes's Introduction

##Ansible journey of an Developer #####Pocket guide to Ansbile in 10 min

###Getting started

Ansible is a configuration management with an agent-less approach, meaning there is no pre-installed software needed in remote machines.

SSH is first-class citizen in terms of conectivity.

ansible is needed only in control machine. To install Ansible from Mac with Brew:

brew install ansible

To verify ansible is successfully installed in control machine

$ ansible --version
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides

###Configuration file Loaded in the following order

* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg

Sample config https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg Documentation http://docs.ansible.com/ansible/intro_configuration.html

###Inventory

Hosts or remote machines are defined in inventory files and can be grouped, nested.

[webservers]
foo.example.com
bar.example.com
www[01:50].example.com

[dbservers]
one.example.com
two.example.com
db-[a:f].example.com

Assign variable per host or per group. However, the preferred practice in Ansible is actually not to store variables in the main inventory file group_vars/groupfoo and host_vars/hostbar

[dev]
devlocal ansible_port=22 ansible_host=192.0.2.50

[atlanta]
host1 http_port=80 maxRequestsPerChild=808

[dev:vars]
self_destruct_countdown=60

Creating group of group

[singapore]
sg1

[hongkong]
hk1

[southeast:children]
singapore
hongkong

###Dynamic Inventory See list of supported vendors https://github.com/ansible/ansible/tree/devel/contrib/inventory

###Host matching pattern

ansible <host_matching_pattern> -m <module_name> -a <arguments>

  • * and all match all hosts
  • *.example.com wildcard matching
  • webservers:dbservers matches hosts in multiple group (OR)
  • webservers:&dev maches hosts belongs to both groups (AND)
  • webservers:!{{excluded}}:&{{required}} using variable
  • ~(web|db).*\.example\.com regex matching

###Ad-hoc command

Execute abitrary command

ansible hosts -a '/bin/echo foo'

Execute module command

ansible webservers -m yum -a "name=acme state=present"

Execute long runing command in the background

ansible all -B 3600 -P 0 -a "/usr/bin/long_running_operation --do-stuff"

##Playbook

Written in yml format, playbook is used to manage and deploy to remote machines. At a more advanced level, playbook can sequence multi-tier rollouts involving rolling updates, and can delegate actions to other hosts, interacting with monitoring servers and load balancers.

###Examples

Official playbook example: https://github.com/ansible/ansible-examples

Openstack Ansible (More serious and real-world scenario): https://github.com/openstack/openstack-ansible/tree/master/playbooks

ansible-notes's People

Contributors

haphan avatar

Stargazers

 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.