2012-03-07 17:35:18 +01:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
2012-03-09 13:42:53 +01:00
< title > Command Line Examples — Ansible v0.0.1 documentation< / title >
2012-03-07 17:35:18 +01:00
< link rel = "stylesheet" href = "_static/default.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/pygments.css" type = "text/css" / >
< script type = "text/javascript" >
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
< / script >
< script type = "text/javascript" src = "_static/jquery.js" > < / script >
< script type = "text/javascript" src = "_static/underscore.js" > < / script >
< script type = "text/javascript" src = "_static/doctools.js" > < / script >
< link rel = "top" title = "Ansible v0.0.1 documentation" href = "index.html" / >
2012-03-09 04:50:12 +01:00
< link rel = "next" title = "Ansible Modules" href = "modules.html" / >
< link rel = "prev" title = "The Inventory File, Patterns, and Groups" href = "patterns.html" / >
2012-03-07 17:35:18 +01:00
< / head >
< body >
< div class = "related" >
< h3 > Navigation< / h3 >
< ul >
< li class = "right" style = "margin-right: 10px" >
< a href = "genindex.html" title = "General Index"
accesskey="I">index< / a > < / li >
< li class = "right" >
2012-03-09 04:50:12 +01:00
< a href = "modules.html" title = "Ansible Modules"
2012-03-07 17:35:18 +01:00
accesskey="N">next< / a > |< / li >
< li class = "right" >
2012-03-09 04:50:12 +01:00
< a href = "patterns.html" title = "The Inventory File, Patterns, and Groups"
2012-03-07 17:35:18 +01:00
accesskey="P">previous< / a > |< / li >
< li > < a href = "index.html" > Ansible v0.0.1 documentation< / a > » < / li >
< / ul >
< / div >
< div class = "document" >
< div class = "documentwrapper" >
< div class = "bodywrapper" >
< div class = "body" >
2012-03-09 13:42:53 +01:00
< div class = "section" id = "command-line-examples" >
< h1 > Command Line Examples< a class = "headerlink" href = "#command-line-examples" title = "Permalink to this headline" > ¶< / a > < / h1 >
< p > The following examples show how to use < cite > /usr/bin/ansible< / cite > for running ad-hoc tasks.
Start here. For configuration management and deployments, you’ ll want to pick up on
using < cite > /usr/bin/ansible-playbook< / cite > – the concepts port over directly.< / p >
2012-03-08 19:36:47 +01:00
< div class = "admonition-see-also admonition seealso" >
< p class = "first admonition-title" > See also< / p >
< dl class = "last docutils" >
< dt > < a class = "reference internal" href = "modules.html" > < em > Ansible Modules< / em > < / a > < / dt >
< dd > A list of available modules< / dd >
2012-03-08 19:53:48 +01:00
< dt > < a class = "reference internal" href = "playbooks.html" > < em > Playbooks: Ansible for Deployment, Configuration Management, and Orchestration< / em > < / a > < / dt >
2012-03-08 19:36:47 +01:00
< dd > Alternative ways to use ansible< / dd >
< / dl >
2012-03-07 17:35:18 +01:00
< / div >
2012-03-08 19:36:47 +01:00
< div class = "section" id = "parallelism-and-shell-commands" >
< h2 > Parallelism and Shell Commands< a class = "headerlink" href = "#parallelism-and-shell-commands" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-09 04:50:12 +01:00
< p > Let’ s use ansible’ s command line tool to reboot all web servers in Atlanta, 10 at a time:< / p >
2012-03-08 19:36:47 +01:00
< div class = "highlight-python" > < pre > ssh-agent bash
ssh-add ~/.ssh/id_rsa.pub
ansible atlanta -a "/sbin/reboot" -f 10< / pre >
< / div >
< p > The -f 10 specifies the usage of 10 simultaneous processes.< / p >
2012-03-09 04:50:12 +01:00
< p > 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’ .< / p >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-09 04:50:12 +01:00
< div class = "section" id = "file-transfer-templating" >
< h2 > File Transfer & Templating< a class = "headerlink" href = "#file-transfer-templating" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-08 19:36:47 +01:00
< p > Ansible can SCP lots of files to multiple machines in parallel, and optionally use them as template sources.< / p >
< p > To just transfer a file directly to many different servers:< / p >
< div class = "highlight-python" > < pre > ansible atlanta copy -a "/etc/hosts /tmp/hosts"< / pre >
< / div >
2012-03-09 04:50:12 +01:00
< p > To use templating, first run the setup module to put the template variables you would like to use on the remote host. Then use the template module to write the files using the templates. Templates are written in Jinja2 format. Playbooks (covered elsewhere in the documentation) will run the setup module for you, making this even simpler.:< / p >
2012-03-08 19:36:47 +01:00
< div class = "highlight-python" > < pre > ansible webservers -m setup -a "favcolor=red ntp_server=192.168.1.1"
ansible webservers -m template -a "src=/srv/motd.j2 dest=/etc/motd"
ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"< / pre >
2012-03-07 17:35:18 +01:00
< / div >
2012-03-08 19:36:47 +01:00
< p > Need something like the fqdn in a template? If facter or ohai are installed, data from these projects will also be made available to the template engine, using ‘ facter’ and ‘ ohai’ prefixes for each.< / p >
2012-03-07 17:35:18 +01:00
< / div >
2012-03-09 04:50:12 +01:00
< div class = "section" id = "deploying-from-source-control" >
< h2 > Deploying From Source Control< a class = "headerlink" href = "#deploying-from-source-control" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-08 19:36:47 +01:00
< p > Deploy your webapp straight from git:< / p >
< div class = "highlight-python" > < pre > ansible webservers -m git -a "repo=git://foo dest=/srv/myapp version=HEAD"< / pre >
2012-03-07 17:35:18 +01:00
< / div >
2012-03-08 19:36:47 +01:00
< p > Since ansible modules can notify change handlers (see ‘ Playbooks’ ) it is possible to tell ansible to run specific tasks when the code is updated, such as deploying Perl/Python/PHP/Ruby directly from git and then restarting apache.< / p >
2012-03-07 17:35:18 +01:00
< / div >
2012-03-09 04:50:12 +01:00
< div class = "section" id = "managing-services" >
< h2 > Managing Services< a class = "headerlink" href = "#managing-services" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > Ensure a service is started on all webservers:< / p >
< div class = "highlight-python" > < pre > ansible webservers -m service name=httpd state=started< / pre >
< / div >
< p > Alternatively, restart a service on all webservers:< / p >
< div class = "highlight-python" > < pre > ansible webservers -m service name=httpd state=restarted< / pre >
< / div >
< / div >
2012-03-09 13:42:53 +01:00
< div class = "section" id = "time-limited-background-operations" >
< h2 > Time Limited Background Operations< a class = "headerlink" href = "#time-limited-background-operations" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > 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.:< / p >
< div class = "highlight-python" > < pre > ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789< / pre >
< / div >
< p > Any module other than ‘ copy’ or ‘ template’ can be backgrounded. Typically you’ ll be backgrounding shell
commands or software upgrades only.< / p >
< p > After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.< / p >
< / div >
2012-03-07 17:35:18 +01:00
< / div >
< / div >
< / div >
< / div >
< div class = "sphinxsidebar" >
< div class = "sphinxsidebarwrapper" >
< h3 > < a href = "index.html" > Table Of Contents< / a > < / h3 >
< ul >
2012-03-09 13:42:53 +01:00
< li > < a class = "reference internal" href = "#" > Command Line Examples< / a > < ul >
2012-03-08 19:36:47 +01:00
< li > < a class = "reference internal" href = "#parallelism-and-shell-commands" > Parallelism and Shell Commands< / a > < / li >
2012-03-09 04:50:12 +01:00
< li > < a class = "reference internal" href = "#file-transfer-templating" > File Transfer & Templating< / a > < / li >
< li > < a class = "reference internal" href = "#deploying-from-source-control" > Deploying From Source Control< / a > < / li >
< li > < a class = "reference internal" href = "#managing-services" > Managing Services< / a > < / li >
2012-03-09 13:42:53 +01:00
< li > < a class = "reference internal" href = "#time-limited-background-operations" > Time Limited Background Operations< / a > < / li >
2012-03-07 17:35:18 +01:00
< / ul >
< / li >
< / ul >
< h4 > Previous topic< / h4 >
2012-03-09 04:50:12 +01:00
< p class = "topless" > < a href = "patterns.html"
title="previous chapter">The Inventory File, Patterns, and Groups< / a > < / p >
2012-03-07 17:35:18 +01:00
< h4 > Next topic< / h4 >
2012-03-09 04:50:12 +01:00
< p class = "topless" > < a href = "modules.html"
title="next chapter">Ansible Modules< / a > < / p >
2012-03-07 17:35:18 +01:00
< h3 > This Page< / h3 >
< ul class = "this-page-menu" >
< li > < a href = "_sources/examples.txt"
rel="nofollow">Show Source< / a > < / li >
< / ul >
< div id = "searchbox" style = "display: none" >
< h3 > Quick search< / h3 >
< form class = "search" action = "search.html" method = "get" >
2012-03-08 19:36:47 +01:00
< input type = "text" name = "q" / >
2012-03-07 17:35:18 +01:00
< input type = "submit" value = "Go" / >
< input type = "hidden" name = "check_keywords" value = "yes" / >
< input type = "hidden" name = "area" value = "default" / >
< / form >
< p class = "searchtip" style = "font-size: 90%" >
Enter search terms or a module, class or function name.
< / p >
< / div >
< script type = "text/javascript" > $ ( '#searchbox' ) . show ( 0 ) ; < / script >
< / div >
< / div >
< div class = "clearer" > < / div >
< / div >
< div class = "related" >
< h3 > Navigation< / h3 >
< ul >
< li class = "right" style = "margin-right: 10px" >
< a href = "genindex.html" title = "General Index"
>index< / a > < / li >
< li class = "right" >
2012-03-09 04:50:12 +01:00
< a href = "modules.html" title = "Ansible Modules"
2012-03-07 17:35:18 +01:00
>next< / a > |< / li >
< li class = "right" >
2012-03-09 04:50:12 +01:00
< a href = "patterns.html" title = "The Inventory File, Patterns, and Groups"
2012-03-07 17:35:18 +01:00
>previous< / a > |< / li >
< li > < a href = "index.html" > Ansible v0.0.1 documentation< / a > » < / li >
< / ul >
< / div >
< div class = "footer" >
© Copyright 2012 Michael DeHaan.
2012-03-09 13:42:53 +01:00
Last updated on Mar 09, 2012.
2012-03-08 19:36:47 +01:00
Created using < a href = "http://sphinx.pocoo.org/" > Sphinx< / a > 1.0.8.
2012-03-07 17:35:18 +01:00
< / div >
< / body >
< / html >