From e8eb7ab5ed723501fab33e4822c27cad64f63eb7 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 9 Mar 2012 07:42:53 -0500 Subject: [PATCH] Update docs --- html/YAMLScripts.html | 2 +- html/_sources/api.txt | 42 ++++++++++- html/_sources/examples.txt | 34 +++++---- html/_sources/playbooks.txt | 55 +++++++++++++- html/api.html | 53 ++++++++++++-- html/communicate.html | 118 ------------------------------- html/examples.html | 35 ++++----- html/genindex.html | 2 +- html/gettingstarted.html | 4 +- html/index.html | 12 ++-- html/man.html | 10 +-- html/man/ansible-modules.5.html | 2 +- html/man/ansible-playbook.5.html | 2 +- html/man/ansible.1.html | 2 +- html/modules.html | 14 ++-- html/patterns.html | 12 ++-- html/playbooks.html | 59 ++++++++++++++-- html/search.html | 2 +- html/searchindex.js | 2 +- rst/api.rst | 42 ++++++++++- rst/examples.rst | 34 +++++---- rst/playbooks.rst | 55 +++++++++++++- 22 files changed, 379 insertions(+), 214 deletions(-) delete mode 100644 html/communicate.html diff --git a/html/YAMLScripts.html b/html/YAMLScripts.html index 09db73f8aea..ec72607e3ca 100644 --- a/html/YAMLScripts.html +++ b/html/YAMLScripts.html @@ -183,7 +183,7 @@ languages: diff --git a/html/_sources/api.txt b/html/_sources/api.txt index a3ddea45951..7eb71cf1f96 100644 --- a/html/_sources/api.txt +++ b/html/_sources/api.txt @@ -1,5 +1,5 @@ -API -``` +Using the Python API +==================== The Python API is very powerful, and is how the ansible CLI and ansible-playbook are implemented. @@ -32,4 +32,42 @@ expressed in the 'ansible-modules' documentation.:: A module can return any type of JSON data it wants, so Ansible can be used as a framework to rapidly build powerful applications and scripts. +Detailed API Example +```````````````````` + +The following script prints out the uptime information for all hosts:: + + #!/usr/bin/python + + import ansible.runner + import sys + + # construct the ansible runner and execute on all hosts + results = ansible.runner.Runner( + pattern='*', forks=10, + module_name='command', module_args=['/usr/bin/uptime'], + ).run() + + if results is None: + print "No hosts found" + sys.exit(1) + + print "UP ***********" + for (hostname, result) in results['contacted'].items(): + if not 'failed' in result: + print "%s >>> %s" % (hostname, result['stdout']) + + print "FAILED *******" + for (hostname, result) in results['contacted'].items(): + if 'failed' in result: + print "%s >>> %s" % (hostname, result['msg']) + + print "DOWN *********" + for (hostname, result) in results['dark'].items(): + print "%s >>> %s" % (hostname, result) + +Advanced programmers may also wish to read the source to ansible itself, for +it uses the Runner() API (with all available options) to implement the +command line tools ``ansible`` and ``ansible-playbook``. + diff --git a/html/_sources/examples.txt b/html/_sources/examples.txt index b061f31eaac..4adeeed94db 100644 --- a/html/_sources/examples.txt +++ b/html/_sources/examples.txt @@ -1,5 +1,9 @@ -Examples -======== +Command Line Examples +===================== + +The following examples show how to use `/usr/bin/ansible` for running ad-hoc tasks. +Start here. For configuration management and deployments, you'll want to pick up on +using `/usr/bin/ansible-playbook` -- the concepts port over directly. .. seealso:: @@ -24,19 +28,6 @@ The -f 10 specifies the usage of 10 simultaneous processes. Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there. This is commonly refered to as 'idempotency'. -Time Limited Background Operations -`````````````````````````````````` - -Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.:: - - ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff" - ansible all -n job_status -a jid=123456789 - -Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell -commands or software upgrades only. - -After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed. - File Transfer & Templating `````````````````````````` @@ -74,4 +65,17 @@ Alternatively, restart a service on all webservers:: ansible webservers -m service name=httpd state=restarted +Time Limited Background Operations +`````````````````````````````````` + +Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.:: + + ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff" + ansible all -n job_status -a jid=123456789 + +Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell +commands or software upgrades only. + +After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed. + diff --git a/html/_sources/playbooks.txt b/html/_sources/playbooks.txt index 71d87d3ee03..890768c5894 100644 --- a/html/_sources/playbooks.txt +++ b/html/_sources/playbooks.txt @@ -47,8 +47,7 @@ back on the webservers group, etc:: Hosts line `````````` -The hosts line is a list of one or more groups or host patterns, seperated by colons, as -described in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible. +The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible. Vars section ```````````` @@ -140,6 +139,58 @@ in a wordpress.yml file, and use it like so:: In addition to the explicitly passed in parameters, all variables from the vars section are also available. +The format of an included list of tasks or handlers looks just like a flat list of tasks. Here +is an example of what base.yml might look like:: + + --- + - name: no selinux + action: command /usr/sbin/setenforce 0 + - name: no iptables + action: service name=iptables state=stopped + - name: this is just to show variables work here, favcolor={{ favcolor }} + action: command /bin/true + +As you can see above, variables in include files work just like they do in the main file. +Including a variable in the name of a task is a contrived example, you could also +pass them to the action command line or use them inside a template file. + +Note that include statements are only usable from the top level playbook file. +At this time, includes can not include other includes. + +Using Includes To Assign Classes of Systems +``````````````````````````````````````````` + +Include files are best used to reuse logic between playbooks. You could imagine +a playbook describing your entire infrastructure like this:: + + --- + - hosts: atlanta-webservers + vars: + datacenter: atlanta + tasks: + - include: base.yml + - include: webservers.yml database=db.atlanta.com + handlers: + - include: generic-handlers.yml + - hosts: atlanta-dbservers + vars: + datacenter: atlanta + tasks: + - include: base.yml + - include: dbservers.yml + handlers: + - include: generic-handlers.yml + +There is one (or more) play defined for each group of systems, and each play maps +each group includes one or more 'class definitions' telling the systems what they +are supposed to do or be. + +Using a common handlers file could allow one task in 'webservers' to define 'restart apache', +and it could be reused between multiple plays. + +Variables like 'database' above can be used in templates referenced from the +configuration file to generate machine specific variables. + Asynchronous Actions and Polling ```````````````````````````````` diff --git a/html/api.html b/html/api.html index 685a15f8c4c..cd965fc710b 100644 --- a/html/api.html +++ b/html/api.html @@ -7,7 +7,7 @@ - API — Ansible v0.0.1 documentation + Using the Python API — Ansible v0.0.1 documentation - - - - - - - - - - -
-
-
-
- -
-

Communicate and Get Involved

- -
- - -
-
-
-
-
-

Previous topic

-

API

-

Next topic

-

Man Pages

-

This Page

- - - -
-
-
-
- - - - \ No newline at end of file diff --git a/html/examples.html b/html/examples.html index d39b37a4b76..d60197c19f8 100644 --- a/html/examples.html +++ b/html/examples.html @@ -7,7 +7,7 @@ - Examples — Ansible v0.0.1 documentation + Command Line Examples — Ansible v0.0.1 documentation - + diff --git a/html/man/ansible-modules.5.html b/html/man/ansible-modules.5.html index d450a830f1c..f1676121f63 100644 --- a/html/man/ansible-modules.5.html +++ b/html/man/ansible-modules.5.html @@ -1,6 +1,6 @@ -ansible-modules

Name

ansible-modules — stock modules shipped with ansible

DESCRIPTION

Ansible ships with a number of modules that can be executed directly on remote hosts or through +ansible-modules

Name

ansible-modules — stock modules shipped with ansible

DESCRIPTION

Ansible ships with a number of modules that can be executed directly on remote hosts or through ansible playbooks.

IDEMPOTENCE

Most modules other than command are idempotent, meaning they will seek to avoid changes unless a change needs to be made. When using ansible playbooks, these modules can trigger change events, as described in ansible-playbooks(5).

Unless otherwise noted, all modules support change hooks.

command

The command module takes the command name followed by a list of arguments, space delimited. diff --git a/html/man/ansible-playbook.5.html b/html/man/ansible-playbook.5.html index e2250d75800..de6d091b1fd 100644 --- a/html/man/ansible-playbook.5.html +++ b/html/man/ansible-playbook.5.html @@ -1,6 +1,6 @@ -ansible-modules

Name

ansible-playbook — format and function of an ansible playbook file

DESCRIPTION

Ansible ships with ansible-playbook, a tool for running playbooks. +ansible-modules

Name

ansible-playbook — format and function of an ansible playbook file

DESCRIPTION

Ansible ships with ansible-playbook, a tool for running playbooks. Playbooks can represent frequent tasks, desired system configurations, or deployment processes.

FORMAT

Playbooks are written in YAML.

EXAMPLE

See:

  • https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml diff --git a/html/man/ansible.1.html b/html/man/ansible.1.html index 41f45554ae7..dab3740bd3b 100644 --- a/html/man/ansible.1.html +++ b/html/man/ansible.1.html @@ -1,6 +1,6 @@ -ansible

    Name

    ansible — run a command somewhere else

    Synopsis

    ansible <host-pattern> [-f forks] [-m module_name] [-a args]

    DESCRIPTION

    Ansible is an extra-simple tool/framework/API for doing 'remote things' over +ansible

    Name

    ansible — run a command somewhere else

    Synopsis

    ansible <host-pattern> [-f forks] [-m module_name] [-a args]

    DESCRIPTION

    Ansible is an extra-simple tool/framework/API for doing 'remote things' over SSH.

    ARGUMENTS

    host-pattern
    diff --git a/html/modules.html b/html/modules.html index 6b91a5d7ee0..3b01f52e5cc 100644 --- a/html/modules.html +++ b/html/modules.html @@ -24,7 +24,7 @@ - +
  • - previous |
  • Ansible v0.0.1 documentation »
@@ -55,11 +55,11 @@ ansible playbooks.

See also

-
Examples
+
Command Line Examples
Examples of using modules in /usr/bin/ansible
Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
Examples of using modules with /usr/bin/ansible-playbook
-
API
+
Using the Python API
Examples of using modules with the Python API
@@ -216,7 +216,7 @@ the command line, passing them arguments just like they would be passed with ans

Previous topic

Examples

+ title="previous chapter">Command Line Examples

Next topic

YAML Format

@@ -252,14 +252,14 @@ the command line, passing them arguments just like they would be passed with ans next |
  • - previous |
  • Ansible v0.0.1 documentation »
  • diff --git a/html/patterns.html b/html/patterns.html index 321977cee65..230ca331748 100644 --- a/html/patterns.html +++ b/html/patterns.html @@ -23,7 +23,7 @@ - + @@ -34,7 +34,7 @@ index
  • - next |
  • See also

    -
    Examples
    +
    Command Line Examples
    Examples of basic commands
    Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
    Learning ansible’s configuration management language
    @@ -124,7 +124,7 @@ webservers:dbservers title="previous chapter">Getting Started

    Next topic

    Examples

    + title="next chapter">Command Line Examples

    This Page

  • diff --git a/html/playbooks.html b/html/playbooks.html index ab3394467ed..58baa5b5a38 100644 --- a/html/playbooks.html +++ b/html/playbooks.html @@ -23,7 +23,7 @@ - + @@ -34,7 +34,7 @@ index
  • - next |
  • Hosts line

    -

    The hosts line is a list of one or more groups or host patterns, seperated by colons, as -described in the ‘patterns’ documentation. This is just like the first parameter to /usr/bin/ansible.

    +

    The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the ‘patterns’ documentation. This is just like the first parameter to /usr/bin/ansible.

    Vars section

    @@ -168,6 +167,51 @@ in a wordpress.yml file, and use it like so:

    In addition to the explicitly passed in parameters, all variables from the vars section are also available.

    +

    The format of an included list of tasks or handlers looks just like a flat list of tasks. Here +is an example of what base.yml might look like:

    +
    ---
    +- name: no selinux
    +  action: command /usr/sbin/setenforce 0
    +- name: no iptables
    +  action: service name=iptables state=stopped
    +- name: this is just to show variables work here, favcolor={{ favcolor }}
    +  action: command /bin/true
    +
    +

    As you can see above, variables in include files work just like they do in the main file. +Including a variable in the name of a task is a contrived example, you could also +pass them to the action command line or use them inside a template file.

    +

    Note that include statements are only usable from the top level playbook file. +At this time, includes can not include other includes.

    +
    +
    +

    Using Includes To Assign Classes of Systems

    +

    Include files are best used to reuse logic between playbooks. You could imagine +a playbook describing your entire infrastructure like this:

    +
    ---
    +- hosts: atlanta-webservers
    +  vars:
    +    datacenter: atlanta
    +  tasks:
    +  - include: base.yml
    +  - include: webservers.yml database=db.atlanta.com
    +  handlers:
    +    - include: generic-handlers.yml
    +- hosts: atlanta-dbservers
    +  vars:
    +    datacenter: atlanta
    +  tasks:
    +  - include: base.yml
    +  - include: dbservers.yml
    +  handlers:
    +    - include: generic-handlers.yml
    +
    +

    There is one (or more) play defined for each group of systems, and each play maps +each group includes one or more ‘class definitions’ telling the systems what they +are supposed to do or be.

    +

    Using a common handlers file could allow one task in ‘webservers’ to define ‘restart apache’, +and it could be reused between multiple plays.

    +

    Variables like ‘database’ above can be used in templates referenced from the +configuration file to generate machine specific variables.

    Asynchronous Actions and Polling

    @@ -198,6 +242,7 @@ are also available.

  • Notify statements
  • Handlers
  • Includes
  • +
  • Using Includes To Assign Classes of Systems
  • Asynchronous Actions and Polling
  • Executing A Playbook
  • @@ -209,7 +254,7 @@ are also available.

    title="previous chapter">YAML Format

    Next topic

    API

    + title="next chapter">Using the Python API

    This Page

    diff --git a/html/search.html b/html/search.html index e870053d704..f3f87515708 100644 --- a/html/search.html +++ b/html/search.html @@ -90,7 +90,7 @@
    diff --git a/html/searchindex.js b/html/searchindex.js index af354f31d25..918c86baa63 100644 --- a/html/searchindex.js +++ b/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({objects:{},terms:{all:[0,1,2,3,4,5,7],rhoncu:[],donec:[],mcollect:1,prefix:[2,3,7],code:[1,2,7],lacu:[],follow:[5,2,3],scp:7,nunc:[],content:[0,1],middl:3,depend:[],fusc:[],elsewher:7,program:[1,2,3],certain:3,vel:[],blindingli:1,spec:3,sourc:[1,2,3,7],everi:[4,3],string:2,fals:[4,2],than:[0,2,3,7],consequat:[],failur:[6,2],veri:[1,6,3],affect:3,risu:[],luctu:[],implement:6,magic:[],level:[4,2],id_rsa:[0,7],list:[1,2,3,4,5,7,8],vivamu:[],item:4,ansible_librari:[],form:[4,3],dotnet:4,saltstack:1,mpdehaan:[],phasellu:[],ornar:[],alic:3,natur:2,seper:3,chef:1,second:[4,7],design:1,pass:[2,3],eleifend:[],further:3,even:7,what:[0,2,3],diam:[],favcolor:7,section:[1,2,3],abl:[],nec:[],abbrevi:4,version:[2,7],directori:[2,3],ever:1,method:6,metadata:[],tar:0,suscipit:[],hash:2,facter_hostnam:3,eckersberg:4,here:2,leo:[],let:[3,7],address:[5,2],path:2,sinc:7,valu:[4,2,3],aliquam:[],scelerisqu:[],great:1,purpos:2,plai:[2,3],ahead:3,precursor:1,larger:[],technolog:1,host:[0,1,2,3,5,6,7],adipisc:[],prior:2,venenati:[],web1:6,permit:4,action:[1,2,3],nulla:[],bob:3,commonli:7,ourselv:3,iaculi:[],via:[0,1],regardless:[4,1,3],dictionari:4,extra:3,modul:[0,1,2,3,6,7],prefer:[],qui:[],unix:3,api:[1,6,2],instal:[7,0,2,3,1],select:[1,2,3,5],httpd:[3,7],from:[0,1,2,3,4,7],describ:[2,3],would:[2,7],commun:1,visit:1,two:[4,0,5],noarch:0,suit:3,live:0,dehaan:1,call:2,usr:[2,3,7],taken:3,sagitti:[],basi:3,checkout:2,until:0,more:[0,5,2,3,1],desir:3,idempot:[2,3,7],dbserver:5,unneccessari:2,sbin:[2,7],agent:[0,7],particular:[1,3],easiest:1,must:[4,2,3],sshd:1,none:[],join:1,ibm:1,module_arg:6,habitass:[],setup:[1,2,7],work:[0,5,7,1],critic:1,remain:1,tag:[0,2],can:[0,1,2,3,4,5,6,7],learn:[0,5,3,1],ero:[],root:[4,1,3],pick:4,control:[1,2,3,7],myapp:7,yamllint:4,ultric:[],process:[1,7],rpath:1,sudo:0,share:2,templat:[7,0,2,3,1],othervar:3,knows_oop:4,minimum:3,want:[6,2,3],occur:3,nullam:[],alwai:2,multipl:[5,3,7],newlin:4,puru:[],sit:[],capistrano:1,ping:[0,6,2,1],write:[4,1,2,3,7],how:[0,2,3,4,5,6],etiam:[],instead:2,simpl:[4,1,6,3,7],updat:7,arcu:[],express:[4,1,6,3],referenc:[5,3],clone:0,after:[3,7],usabl:1,befor:[2,3],ohai_:3,mai:[4,0],end:[2,3],data:[4,6,2,7],parallel:[1,7],man:[1,8],repo:[2,7],"short":1,orchestr:[0,1,2,3,5,7],thoug:2,read:[4,0],bootstrap:1,favorit:1,turpi:[],element:[4,2],issu:1,inform:[2,3],mango:4,combin:4,asynchron:[1,3],order:3,talk:[0,3],oper:[1,7],help:1,over:1,move:[2,3],orang:4,becaus:[],elit:4,rpmbuild:0,comma:4,vita:[],still:[],paramet:[2,3],facter_:3,jid:7,overlord:0,group:[1,6,3,5],cli:6,fit:[],yaml:[4,1,3],pend:[3,7],rapidli:6,infrastructur:[0,5,1],mail:[1,5],sapien:[],main:3,might:3,easier:[],non:1,"return":[1,6,2],thei:[6,2,3,7],food:4,alist:[],nibh:[],egesta:[],"break":[],framework:[1,6],jinja2:[0,2,3,7],now:[0,2],nor:2,choic:1,multiprocess:0,name:[4,1,2,3,7],anyth:2,neccessari:[2,7],config:[1,3],viverra:[],drop:2,datastructur:6,porta:[],separ:4,each:[4,2,3,7],puppet:1,stock:2,nearli:[2,3],mean:[2,3],harm:3,metu:[],michael:1,auctor:[],idea:1,realli:[4,2,3],contributor:[],backport:0,connect:[],our:4,happen:[2,3],todo:[],event:2,out:[4,1,2,3,7],variabl:[2,3,7],"try":[],shown:[],network:1,space:[1,2],reboot:7,bubbl:[2,3],stuff:7,rel:2,internet:1,correct:[4,1,3],red:[1,7],rotat:3,state:[2,3,7],hendrerit:[],ntp:7,contain:[2,3],differ:[7,0,3,1],pub:7,base:[1,3],lab:1,tempu:[],releas:0,org:0,molli:[],bash:[0,7],care:[],vestibulum:[],pyyaml:0,indent:[],maecena:[],could:[6,3],put:[0,7],fqdn:7,thing:[1,3],yum:[],isn:1,principl:[],top:2,first:[7,0,2,3,1],origin:1,softwar:[1,2,7],rang:1,notifi:[1,3,7],obviou:1,onc:[2,3],number:2,yourself:0,hook:2,instruct:0,alreadi:[0,2,3],done:3,fast:1,enim:[],massiv:1,open:[],straight:7,given:[2,7],convent:2,script:[1,6,7],associ:4,licens:[],mkdir:3,system:[0,1,2,3,5,7],messag:6,grow:[],too:1,statement:[1,3],molesti:[],john:4,banana:4,includ:[1,3],shell:[1,2,7],option:[4,8,3,7],welcom:1,tool:[1,2,7],copi:[1,2,7],specifi:[4,2,7],retyp:0,quam:[],next:3,github:[0,1],kept:3,exactli:[],accumsan:[],serv:[],liter:2,silli:3,target:[1,5],provid:4,sollicitudin:[],heavyweight:[],structur:4,charact:4,project:[0,7,1],architect:1,were:3,tion:4,uses_cv:4,pre:0,sai:3,runner:6,explicit:2,ani:[1,6,2,3,7],spent:[],ant:[],download:0,have:[0,3,1],need:[4,0,2,3,7],tellu:[],seek:2,paramiko:0,engin:7,built:0,contact:[0,6,2],note:[5,2,7],also:[0,1,2,3,4,5,7],client:1,massa:[],build:[0,6],indic:2,environ:[],divers:1,pulvinar:[],begin:4,sure:[],unless:2,distribut:[0,1],deploy:[0,1,2,3,5,7],track:7,who:[],discov:3,most:[4,2],employe:4,regular:3,plan:[],deploi:[1,2,3,7],pair:2,why:1,porttitor:[],simplic:[],don:2,doc:1,later:7,cover:7,doe:[1,2,5],sodal:[],bracket:[4,5],snapshot:2,place:1,wildcard:5,dolor:[],someth:[1,2,7],awesom:[1,3],laoreet:[],blandit:[],verbos:2,syntax:[4,3],bring:3,directli:[2,3,7],raleigh:1,particularli:3,playbook:[0,1,2,3,4,5,6,7],permiss:[],hack:1,radic:1,pki:[],trivial:[1,2],varnam:3,involv:1,absolut:2,onli:[0,2,3,7],explicitli:3,locat:2,just:[7,0,2,3,1],pretti:6,configur:[0,1,2,3,4,5,7],apach:[3,7],written:[1,2,3,7],should:[4,2],consectetur:[],somevar:3,congratul:0,variu:[],local:2,yml:3,long_running_oper:7,contribut:1,variou:[],get:[4,0,3,7,1],financ:1,stop:2,mission:1,bibendum:[],ssl:[],ssh:[0,7],malesuada:[],requir:[0,2,1],uvh:0,nisi:[],bar:5,lame:4,nisl:[],remot:[0,2,3,7],cra:[],orci:[],through:[0,2,1],told:3,where:[1,2,3],wrote:[],view:[1,8],set:[0,2,3],creator:[],elimin:[],see:[0,1,2,3,4,5,7],sed:[],result:[6,2],fail:3,sem:[],extend:1,ntp_server:7,faucibu:[],statu:7,kei:[4,0,2,3],databas:3,modularli:[],discoveri:2,restart:[2,3,7],behind:2,won:7,languag:[4,0,5,2,1],between:4,"import":6,irc:1,altern:7,elementum:[],manpag:[0,8],handful:[],aspir:[],style:2,extens:1,job:[4,7],entir:3,aserv:0,magna:[],webapp:7,timmi:3,addit:[4,1,3],delimit:2,plugin:[],goal:1,against:[1,3,5],tempor:[],etc:[7,0,5,3,1],instanc:3,mani:[3,7],placerat:[],com:[0,6,5],proin:[],sha:2,minut:[],assur:3,simpli:[2,3],author:1,overview:4,format:[1,2,3,4,5,7],inspir:[],header:5,colon:3,shutdown:2,linux:[1,3],poll:[1,3,7],rpm:[0,1],matti:[],dui:[],three:5,pretium:[],multiplay:1,morbi:[],compos:3,been:1,amet:[],json:[1,6,2],much:[1,2],basic:[4,0,5,2,1],ungroup:[],feugiat:[],quickli:[4,1],indenta:4,box:[1,2],derefer:[],fire:1,rubi:[4,2,7],vulput:[],argument:2,understand:[],pellentesqu:[],func:1,atlanta:7,job_statu:7,those:[4,2],emploi:4,authorized_kei:0,multi:[1,3],tortor:[],look:[5,3,7],nequ:[],hoc:[1,3],servic:[1,2,3,7],md5sum:2,batch:[],"while":3,overrid:[],abov:3,ipsum:[],cobbler:1,scene:2,real:0,motd:[3,7],max_client:3,them:[2,3,7],erat:[],conf:[3,7],module_nam:6,ship:2,sever:4,http_port:3,develop:[4,0,1],inventori:[1,2,3,5],minim:0,make:[0,2,3,7],platea:[],same:[4,5,7],member:4,python:[0,1,2,4,6,7],complex:[1,3],success:2,fedora:[],document:[0,6,3,7],ansibl:[0,1,2,3,4,5,6,7,8],complet:3,finish:[],http:2,hostnam:3,again:3,nest:2,painless:1,effect:3,dai:[],fruit:4,user:3,ownership:[],extrem:0,php:7,distutil:[0,1],typic:7,squar:4,exceedingli:[],task:[1,3,7],off:1,scenario:2,mention:3,whole:[],well:[0,2,3],hypothet:3,exampl:[0,1,2,3,4,5,6,7],command:[0,1,2,3,5,7,8],thi:[0,1,2,3,4,5,7],choos:2,dereferenc:3,usual:3,comment:[],protocol:2,execut:[1,2,3],less:[0,1],when:[2,3,7],kill:7,skill:4,simultan:7,ligula:[],previous:[],web:[6,7],versu:1,easi:[1,2],mix:5,trigger:2,hac:[],except:3,littl:1,add:[0,7],other:[7,0,2,3,1],els:1,unlik:3,hat:1,match:3,take:2,bin:[0,2,3,7],applic:[6,3],which:[4,0,5,3,1],ohai:[1,2,3,7],dest:[2,3,7],tincidunt:[],dark:6,game:1,know:[4,2,3],background:[1,7],world:0,bit:2,password:0,daemon:1,motorola:1,like:[4,5,2,3,7],specif:[5,6,7],signal:3,manual:[],integ:2,noth:3,edit:0,"boolean":4,either:2,velit:[],popular:1,async:[],page:[4,0,8,1],deal:[],webserv:[5,3,7],suppli:[],some:[0,2],back:3,dead:1,tumblr:[],home:[],server:[1,2,3,7],librari:[],tmp:[3,7],render:2,assum:3,avoid:[0,2],though:1,ultrici:[],per:6,tracker:1,unit:[],pattern:[1,6,3,5],foo:[5,7],complic:1,refer:7,machin:[0,2,3,7],core:1,run:[0,6,2,3,7],power:[1,6],quit:[],lose:7,usag:[2,7],asciidoc:0,web2:6,step:[2,3],explor:0,repositori:0,output:3,"super":1,aenean:[],simpler:7,comparison:1,about:[4,0,2,3,1],actual:2,gplv3:[],justo:[],libero:[],surround:4,manag:[0,1,2,3,4,5,7],srv:[3,7],quisqu:[],industri:1,own:[1,2,3],"final":4,bounc:2,within:2,automat:2,upgrad:7,down:[],ensur:[3,7],chang:[2,3,7],perl:7,bserver:0,your:[0,1,2,3,4,5,7],praesent:[],git:[0,2,7,1],type:6,fabric:1,wai:[4,0,3,7],interdum:[],transfer:[1,7],dictum:[],support:[2,7],question:1,"long":[1,2,7],happi:1,avail:[0,8,2,3,7],start:[0,1,2,3,4,7],appl:4,wordpress:3,augu:[],lot:[1,3,7],replac:3,"var":[1,3],individu:5,fork:6,head:[2,7],doctyp:[],simplejson:0,eget:[],handler:[1,3,7],lint:4,yeah:3,msg:2,loborti:[],ullamcorp:[],line:[1,2,3,4,7,8],"true":[4,2],tristiqu:[],freenod:1,info:3,strawberri:4,made:[2,7],possibl:[5,3,7],whether:6,wish:[4,0,5],caller:2,tell:[2,7],planet:1,record:4,below:[],limit:[1,7],suspendiss:[],rerun:3,otherwis:2,problem:[],similar:2,chip:1,facter:[1,2,3,7],curv:1,featur:3,tasti:4,creat:1,lectu:[],doesn:1,repres:4,ansil:[],deferenc:3,file:[0,1,2,3,4,5,7],mauri:[],exist:[1,3],check:[2,7],urna:[],conval:[],echo:0,denot:5,googl:1,excel:1,nam:[],"default":[1,5],likes_emac:4,futur:0,dignissim:[],test:[0,2],you:[0,1,2,3,4,5,7],clojur:[],node:[0,2,7,1],dapibu:[],journei:[],gravida:[],sequenc:1,devop:1,push:3,est:[],log:3,feli:[],aliquet:[],src:[2,3,7],lorem:[],"60k":1,dictumst:[],sphinx:0,rutrum:[],anywher:[],descript:[],portion:5,emerg:1,potenti:3,time:[0,1,2,3,5,7],far:1,serious:[],fermentum:[],hello:0},objtypes:{},titles:["Getting Started","Ansible","Ansible Modules","Playbooks: Ansible for Deployment, Configuration Management, and Orchestration","YAML Format","The Inventory File, Patterns, and Groups","API","Examples","Man Pages"],objnames:{},filenames:["gettingstarted","index","modules","playbooks","YAMLScripts","patterns","api","examples","man"]}) \ No newline at end of file +Search.setIndex({objects:{},terms:{all:[0,1,2,3,4,5,6,7],code:[1,2,7],myapp:7,perl:7,mcollect:1,prefix:[2,3,7],concept:7,upgrad:7,follow:[5,6,2,3,7],scp:7,content:[0,1],middl:3,elsewher:7,specif:[5,6,3,7],program:[1,2,3],selinux:3,blindingli:1,spec:3,sourc:[1,6,2,3,7],everi:[4,3],string:2,fals:[4,2],failur:[6,2],veri:[1,6,3],affect:3,max_client:3,level:[4,2,3],id_rsa:[0,7],list:[1,2,3,4,5,7,8],item:[4,6],dotnet:4,saltstack:1,servic:[1,2,3,7],alic:3,natur:2,seper:3,chef:1,second:[4,7],design:1,pass:[2,3],download:0,further:3,port:7,even:7,what:[0,2,3],favcolor:[3,7],section:[1,2,3],abbrevi:4,version:[2,7],varnam:3,ever:1,method:6,told:3,hash:2,facter_hostnam:3,eckersberg:4,gener:3,here:[2,3,7],let:[3,7],address:[5,2],path:2,sinc:7,valu:[4,2,3],box:[1,2],great:1,ahead:3,precursor:1,technolog:1,host:[0,1,2,3,5,6,7],prior:2,pick:[4,7],action:[1,2,3],extrem:0,implement:6,commonli:7,ourselv:3,employe:4,via:[0,1],regardless:[4,1,3],extra:3,modul:[0,1,2,3,6,7],put:[0,7],unix:3,"boolean":4,instal:[7,0,2,3,1],select:[1,2,3,5],httpd:[3,7],from:[0,1,2,3,4,7],describ:[2,3],would:[2,7],commun:1,visit:1,two:[4,0,5],noarch:0,suit:3,live:0,handler:[1,3,7],call:2,usr:[6,2,3,7],msg:[6,2],somevar:3,type:6,tell:[2,3,7],more:[0,5,2,3,1],flat:3,desir:3,idempot:[2,3,7],src:[2,3,7],unneccessari:2,sshd:1,agent:[0,7],particular:[1,3],easiest:1,must:[4,2,3],none:6,join:1,ibm:1,module_arg:6,setup:[1,2,7],work:[7,0,5,3,1],knows_oop:4,remain:1,tag:[0,2],can:[0,1,2,3,4,5,6,7],learn:[0,5,3,1],about:[4,0,2,3,1],purpos:2,root:[4,1,3],control:[1,2,3,7],want:[6,2,3,7],yamllint:4,process:[1,7],rpath:1,sudo:0,share:2,templat:[7,0,2,3,1],critic:1,minimum:3,explor:0,occur:3,contribut:1,alwai:2,multipl:[5,3,7],newlin:4,thoug:2,lame:4,capistrano:1,ping:[0,6,2,1],uptim:6,write:[4,1,2,3,7],how:[0,2,3,4,5,6,7],instead:2,config:[1,3],stock:2,map:3,express:[4,1,6,3],referenc:[5,3],clone:0,after:[3,7],lab:1,befor:[2,3],ohai_:3,mai:[4,0,6],end:[2,3],associ:4,parallel:[1,7],man:[1,8],"short":1,orchestr:[0,1,2,3,5,7],read:[4,0,6],bootstrap:1,explicit:2,element:[4,2],issu:1,inform:[6,2,3],mango:4,combin:4,allow:3,order:3,talk:[0,3],origin:1,help:1,over:[1,7],move:[2,3],orang:4,mission:1,elit:4,rpmbuild:0,comma:4,paramet:[2,3],facter_:3,jid:7,overlord:0,group:[1,6,3,5],cli:6,yaml:[4,1,3],pend:[3,7],rapidli:6,infrastructur:[0,5,3,1],mail:[1,5],job_statu:7,main:3,might:3,them:[2,3,7],"return":[1,6,2],thei:[6,2,3,7],food:4,scene:2,framework:[1,6],jinja2:[0,2,3,7],now:[0,2],nor:2,choic:1,multiprocess:0,name:[4,1,2,3,7],anyth:2,neccessari:[2,7],simpl:[4,1,6,3,7],drop:2,instruct:0,separ:4,exampl:[0,1,2,3,4,5,6,7],each:[4,2,3,7],found:6,updat:7,mean:[2,3],harm:3,michael:1,individu:5,idea:1,realli:[4,2,3],backport:0,facter:[1,2,3,7],our:4,happen:[2,3],event:2,out:[1,2,3,4,6,7],variabl:[2,3,7],network:1,space:[1,2],reboot:7,bubbl:[2,3],rel:2,internet:1,print:6,correct:[4,1,3],red:[1,7],insid:3,advanc:6,ntp:7,given:[2,7],pub:7,base:[1,3],usabl:[1,3],dictionari:4,releas:0,org:0,bash:[0,7],basi:3,pyyaml:0,could:[6,3],fqdn:7,thing:[1,3],place:1,isn:1,assign:[1,3],first:[7,0,2,3,1],oper:[1,7],softwar:[1,2,7],rang:1,notifi:[1,3,7],directli:[2,3,7],onc:[2,3],number:2,yourself:0,hook:2,datastructur:6,alreadi:[0,2,3],puppet:1,construct:6,extend:1,massiv:1,differ:[7,0,3,1],"long":[1,2,7],convent:2,script:[1,6,7],data:[4,6,2,7],top:[2,3],mkdir:3,system:[0,1,2,3,5,7],messag:6,appl:4,too:1,statement:[1,3],john:4,banana:4,iptabl:3,shell:[1,2,7],option:[4,6,3,8,7],welcom:1,tool:[1,6,2,7],copi:[1,2,7],specifi:[4,2,7],retyp:0,provid:4,github:[0,1],off:1,than:[0,2,3,7],liter:2,silli:3,target:[1,5],remot:[0,2,3,7],structur:4,"final":4,project:[0,7,1],reus:3,architect:1,were:3,tion:4,uses_cv:4,pre:0,sai:3,runner:6,favorit:1,ani:[1,6,2,3,7],have:[0,3,1],need:[4,0,2,3,7],seek:2,paramiko:0,imagin:3,engin:7,built:0,note:[5,2,3,7],also:[0,1,2,3,4,5,6,7],client:1,build:[0,6],indic:2,datacent:3,divers:1,begin:4,unless:2,distribut:[0,1],deploy:[0,1,2,3,5,7],track:7,discov:3,most:[4,2],plai:[2,3],regular:3,deploi:[1,2,3,7],pair:2,why:1,don:2,doc:1,later:7,cover:7,doe:[1,2,5],likes_emac:4,snapshot:2,wildcard:5,pattern:[1,6,3,5],awesom:[1,3],show:[3,7],verbos:2,syntax:[4,3],bring:3,raleigh:1,particularli:3,playbook:[0,1,2,3,4,5,6,7],hack:1,radic:1,trivial:[1,2],rotat:3,involv:1,absolut:2,onli:[0,2,3,7],explicitli:3,locat:2,execut:[1,6,2,3],pretti:6,configur:[0,1,2,3,4,5,7],apach:[3,7],state:[2,3,7],should:[4,2],suppos:3,congratul:0,local:2,yml:3,long_running_oper:7,nearli:[2,3],get:[4,0,3,7,1],financ:1,stop:[2,3],repo:[2,7],obviou:1,ssh:[0,7],requir:[0,2,1],uvh:0,bar:5,sha:2,stuff:7,common:3,contain:[2,3],through:[0,2,1],where:[1,2,3],view:[1,8],set:[0,2,3],see:[0,1,2,3,4,5,7],result:[6,2],fail:[6,3],charact:4,skill:4,best:3,asynchron:[1,3],statu:7,kei:[4,0,2,3],databas:3,someth:[1,2,7],discoveri:2,restart:[2,3,7],behind:2,won:7,between:[4,3],"import":6,irc:1,altern:7,manpag:[0,8],style:2,extens:1,job:[4,7],entir:3,aserv:0,webapp:7,asdescrib:3,timmi:3,addit:[4,1,3],delimit:2,goal:1,against:[1,3,5],etc:[7,0,5,3,1],instanc:3,logic:3,mani:[3,7],com:[0,6,3,5],assur:3,simpli:[2,3],overview:4,header:5,written:[1,2,3,7],colon:3,shutdown:2,linux:[1,3],poll:[1,3,7],rpm:[0,1],multiplay:1,three:5,been:1,json:[1,6,2],much:[1,2],far:1,basic:[4,0,5,2,1],quickli:[4,1],indenta:4,wish:[4,0,6,5],fire:1,rubi:[4,2,7],argument:2,func:1,minim:0,atlanta:[3,7],those:[4,2],emploi:4,authorized_kei:0,multi:[1,3],look:[5,3,7],hoc:[1,3,7],straight:7,md5sum:2,permit:4,defin:3,"while":3,abov:3,exist:[1,3],dehaan:1,motd:[3,7],tar:0,stdout:6,non:1,itself:6,conf:[3,7],module_nam:6,sever:4,http_port:3,develop:[4,0,1],inventori:[1,2,3,5],author:1,make:[0,2,3,7],format:[1,2,3,4,5,7],same:[4,5,7],member:4,python:[0,1,2,4,6,7],complex:[1,3],document:[0,6,3,7],ansibl:[0,1,2,3,4,5,6,7,8],complet:3,http:2,hostnam:[6,3],denot:5,nest:2,painless:1,effect:3,fruit:4,user:3,php:7,distutil:[0,1],typic:7,squar:4,task:[1,3,7],kept:3,scenario:2,mention:3,setenforc:3,well:[0,2,3],hypothet:3,contact:[0,6,2],command:[0,1,2,3,5,6,7,8],thi:[0,1,2,3,4,5,7],choos:2,programm:6,dereferenc:3,usual:3,protocol:2,just:[7,0,2,3,1],less:[0,1],when:[2,3,7],kill:7,ntp_server:7,simultan:7,languag:[4,0,5,2,1],web:[6,7],versu:1,easi:[1,2],mix:5,except:3,littl:1,add:[0,7],other:[7,0,2,3,1],simplejson:0,els:1,unlik:3,hat:1,match:3,take:2,bin:[0,6,2,3,7],applic:[6,3],which:[4,0,5,3,1],ohai:[1,2,3,7],dest:[2,3,7],dark:6,game:1,know:[4,2,3],background:[1,7],world:0,bit:2,password:0,daemon:1,motorola:1,like:[4,5,2,3,7],success:2,signal:3,integ:2,noth:3,edit:0,api:[1,6,2],either:2,lose:7,popular:1,output:3,manag:[0,1,2,3,4,5,7],webserv:[5,3,7],some:[0,2],back:3,dead:1,server:[1,2,3,7],tmp:[3,7],render:2,assum:3,avoid:[0,2],though:1,definit:3,per:6,tracker:1,exit:6,foo:[5,7],complic:1,refer:7,machin:[0,2,3,7],core:1,run:[0,6,2,3,7],power:[1,6],usag:[2,7],asciidoc:0,web2:6,step:[2,3],web1:6,repositori:0,"super":1,simpler:7,comparison:1,sbin:[2,3,7],actual:2,othervar:3,surround:4,page:[4,0,8,1],srv:[3,7],done:3,industri:1,own:[1,2,3],real:0,bounc:2,within:2,contriv:3,automat:2,compos:3,down:6,ensur:[3,7],chang:[2,3,7],next:3,bserver:0,your:[0,1,2,3,4,5,7],git:[0,2,7,1],fabric:1,wai:[4,0,3,7],transfer:[1,7],support:[2,7],question:1,fast:1,happi:1,avail:[0,2,3,6,7,8],start:[0,1,2,3,4,7],trigger:2,wordpress:3,includ:[1,3],lot:[1,3,7],replac:3,"var":[1,3],fork:6,head:[2,7],form:[4,3],lint:4,yeah:3,taken:3,line:[0,1,2,3,4,5,6,7,8],"true":[4,2,3],freenod:1,info:3,strawberri:4,made:[2,7],possibl:[5,3,7],whether:6,checkout:2,caller:2,until:0,planet:1,record:4,limit:[1,7],rerun:3,otherwis:2,similar:2,chip:1,curv:1,featur:3,tasti:4,creat:1,certain:3,doesn:1,repres:4,cobbler:1,file:[0,1,2,3,4,5,7],bob:3,ship:2,check:[2,7],echo:0,again:3,googl:1,dbserver:[5,3],excel:1,detail:[1,6],"default":[1,5],bracket:[4,5],futur:0,test:[0,2],you:[0,1,2,3,4,5,7],node:[0,2,7,1],sequenc:1,"class":[1,3],devop:1,log:3,deferenc:3,"60k":1,sphinx:0,directori:[2,3],portion:5,emerg:1,potenti:3,time:[0,1,2,3,5,7],push:3,hello:0},objtypes:{},titles:["Getting Started","Ansible","Ansible Modules","Playbooks: Ansible for Deployment, Configuration Management, and Orchestration","YAML Format","The Inventory File, Patterns, and Groups","Using the Python API","Command Line Examples","Man Pages"],objnames:{},filenames:["gettingstarted","index","modules","playbooks","YAMLScripts","patterns","api","examples","man"]}) \ No newline at end of file diff --git a/rst/api.rst b/rst/api.rst index a3ddea45951..7eb71cf1f96 100644 --- a/rst/api.rst +++ b/rst/api.rst @@ -1,5 +1,5 @@ -API -``` +Using the Python API +==================== The Python API is very powerful, and is how the ansible CLI and ansible-playbook are implemented. @@ -32,4 +32,42 @@ expressed in the 'ansible-modules' documentation.:: A module can return any type of JSON data it wants, so Ansible can be used as a framework to rapidly build powerful applications and scripts. +Detailed API Example +```````````````````` + +The following script prints out the uptime information for all hosts:: + + #!/usr/bin/python + + import ansible.runner + import sys + + # construct the ansible runner and execute on all hosts + results = ansible.runner.Runner( + pattern='*', forks=10, + module_name='command', module_args=['/usr/bin/uptime'], + ).run() + + if results is None: + print "No hosts found" + sys.exit(1) + + print "UP ***********" + for (hostname, result) in results['contacted'].items(): + if not 'failed' in result: + print "%s >>> %s" % (hostname, result['stdout']) + + print "FAILED *******" + for (hostname, result) in results['contacted'].items(): + if 'failed' in result: + print "%s >>> %s" % (hostname, result['msg']) + + print "DOWN *********" + for (hostname, result) in results['dark'].items(): + print "%s >>> %s" % (hostname, result) + +Advanced programmers may also wish to read the source to ansible itself, for +it uses the Runner() API (with all available options) to implement the +command line tools ``ansible`` and ``ansible-playbook``. + diff --git a/rst/examples.rst b/rst/examples.rst index b061f31eaac..4adeeed94db 100644 --- a/rst/examples.rst +++ b/rst/examples.rst @@ -1,5 +1,9 @@ -Examples -======== +Command Line Examples +===================== + +The following examples show how to use `/usr/bin/ansible` for running ad-hoc tasks. +Start here. For configuration management and deployments, you'll want to pick up on +using `/usr/bin/ansible-playbook` -- the concepts port over directly. .. seealso:: @@ -24,19 +28,6 @@ The -f 10 specifies the usage of 10 simultaneous processes. Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there. This is commonly refered to as 'idempotency'. -Time Limited Background Operations -`````````````````````````````````` - -Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.:: - - ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff" - ansible all -n job_status -a jid=123456789 - -Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell -commands or software upgrades only. - -After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed. - File Transfer & Templating `````````````````````````` @@ -74,4 +65,17 @@ Alternatively, restart a service on all webservers:: ansible webservers -m service name=httpd state=restarted +Time Limited Background Operations +`````````````````````````````````` + +Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.:: + + ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff" + ansible all -n job_status -a jid=123456789 + +Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell +commands or software upgrades only. + +After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed. + diff --git a/rst/playbooks.rst b/rst/playbooks.rst index 71d87d3ee03..890768c5894 100644 --- a/rst/playbooks.rst +++ b/rst/playbooks.rst @@ -47,8 +47,7 @@ back on the webservers group, etc:: Hosts line `````````` -The hosts line is a list of one or more groups or host patterns, seperated by colons, as -described in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible. +The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible. Vars section ```````````` @@ -140,6 +139,58 @@ in a wordpress.yml file, and use it like so:: In addition to the explicitly passed in parameters, all variables from the vars section are also available. +The format of an included list of tasks or handlers looks just like a flat list of tasks. Here +is an example of what base.yml might look like:: + + --- + - name: no selinux + action: command /usr/sbin/setenforce 0 + - name: no iptables + action: service name=iptables state=stopped + - name: this is just to show variables work here, favcolor={{ favcolor }} + action: command /bin/true + +As you can see above, variables in include files work just like they do in the main file. +Including a variable in the name of a task is a contrived example, you could also +pass them to the action command line or use them inside a template file. + +Note that include statements are only usable from the top level playbook file. +At this time, includes can not include other includes. + +Using Includes To Assign Classes of Systems +``````````````````````````````````````````` + +Include files are best used to reuse logic between playbooks. You could imagine +a playbook describing your entire infrastructure like this:: + + --- + - hosts: atlanta-webservers + vars: + datacenter: atlanta + tasks: + - include: base.yml + - include: webservers.yml database=db.atlanta.com + handlers: + - include: generic-handlers.yml + - hosts: atlanta-dbservers + vars: + datacenter: atlanta + tasks: + - include: base.yml + - include: dbservers.yml + handlers: + - include: generic-handlers.yml + +There is one (or more) play defined for each group of systems, and each play maps +each group includes one or more 'class definitions' telling the systems what they +are supposed to do or be. + +Using a common handlers file could allow one task in 'webservers' to define 'restart apache', +and it could be reused between multiple plays. + +Variables like 'database' above can be used in templates referenced from the +configuration file to generate machine specific variables. + Asynchronous Actions and Polling ````````````````````````````````