312 lines
7.8 KiB
HTML
312 lines
7.8 KiB
HTML
<!doctype html>
|
|
<html lang='en' class='no-js '>
|
|
<head>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<meta charset='utf-8'>
|
|
<meta content='width=device-width, initial-scale=1.0' name='viewport'>
|
|
<link href='./assets/favicon.png' rel='shortcut icon'>
|
|
<meta content='/ansible.html' name='app:pageurl'>
|
|
|
|
|
|
<title>Ansible cheatsheet</title>
|
|
<meta content='Ansible cheatsheet' property='og:title'>
|
|
<meta content='Ansible cheatsheet' property='twitter:title'>
|
|
<meta content='article' property='og:type'>
|
|
|
|
|
|
|
|
<meta content='https://assets.devhints.io/previews/ansible.jpg?t=20200704133443' property='og:image'>
|
|
<meta content='https://assets.devhints.io/previews/ansible.jpg?t=20200704133443' property='twitter:image'>
|
|
<meta content='900' property='og:image:width'>
|
|
<meta content='471' property='og:image:height'>
|
|
|
|
|
|
|
|
<meta content="The one-page guide to Ansible: usage, examples, links, snippets, and more." name="description">
|
|
<meta content="The one-page guide to Ansible: usage, examples, links, snippets, and more." property="og:description">
|
|
<meta content="The one-page guide to Ansible: usage, examples, links, snippets, and more." property="twitter:description">
|
|
|
|
|
|
<link rel="canonical" href="https://devhints.io/ansible">
|
|
<meta name="og:url" content="https://devhints.io/ansible">
|
|
|
|
|
|
|
|
|
|
|
|
<meta content='Devhints.io cheatsheets' property='og:site_name'>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<meta content='Ansible' property='article:section'>
|
|
|
|
|
|
|
|
|
|
|
|
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-106902774-1'></script>
|
|
<script>
|
|
|
|
window.dataLayer=window.dataLayer||[];
|
|
function gtag(){dataLayer.push(arguments)};
|
|
gtag('js',new Date());
|
|
gtag('config','UA-106902774-1');
|
|
</script>
|
|
|
|
|
|
|
|
<meta property='page:depth' content='1'>
|
|
|
|
|
|
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
|
|
<script>(function(H){H.className=H.className.replace(/\bNoJs\b/,'WithJs')})(document.documentElement)</script>
|
|
|
|
<script>(function(d,s){if(window.Promise&&[].includes&&Object.assign&&window.Map)return;var js,sc=d.getElementsByTagName(s)[0];js=d.createElement(s);js.src='https://cdn.polyfill.io/v2/polyfill.min.js';sc.parentNode.insertBefore(js, sc);}(document,'script'))</script>
|
|
|
|
<!--[if lt IE 9]><script src='https://cdnjs.cloudflare.com/ajax/libs/nwmatcher/1.2.5/nwmatcher.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/json2/20140204/json2.js'></script><script src='https://cdn.rawgit.com/gisu/selectivizr/1.0.3/selectivizr.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script><![endif]-->
|
|
|
|
<style>html{opacity:0}</style>
|
|
<link rel="stylesheet" href="./assets/2015/style.css?t=20200704133443">
|
|
<link href="./assets/style.css?t=20200704133443" rel="stylesheet" />
|
|
<link href="./assets/print.css?t=20200704133443" rel="stylesheet" media="print" />
|
|
</head>
|
|
<body>
|
|
<div class='all'>
|
|
|
|
<div class='site-header'>
|
|
<div class='container'>
|
|
This is <a href="."><em>Devhints.io cheatsheets</em></a> — a collection of cheatsheets I've written.
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<script type='application/ld+json'>
|
|
{
|
|
"@context": "http://schema.org",
|
|
"@type": "NewsArticle",
|
|
"mainEntityOfPage": {
|
|
"@type": "WebPage",
|
|
"@id": "https://google.com/article"
|
|
},
|
|
"headline": "Ansible cheatsheet",
|
|
"image": [ "https://assets.devhints.io/previews/ansible.jpg?t=20200704133443" ],
|
|
"description": "The one-page guide to Ansible: usage, examples, links, snippets, and more."
|
|
}
|
|
</script>
|
|
<script type='application/ld+json'>
|
|
{
|
|
"@context": "http://schema.org",
|
|
"@type": "BreadcrumbList",
|
|
"itemListElement": [{
|
|
"@type": "ListItem",
|
|
"position": 1,
|
|
"item": {
|
|
"@id": "https://devhints.io/#ansible",
|
|
"name": "Ansible"
|
|
}
|
|
},{
|
|
"@type": "ListItem",
|
|
"position": 2,
|
|
"item": {
|
|
"@id": "https://devhints.io/ansible",
|
|
"name": "Ansible"
|
|
}
|
|
}]
|
|
}
|
|
</script>
|
|
|
|
|
|
<div class='post-list -single -cheatsheet'>
|
|
<div class='post-item'>
|
|
<div class='post-headline -cheatsheet'>
|
|
<p class='prelude'><span></span></p>
|
|
<h1><span>Ansible</span></h1>
|
|
|
|
<div class='pubbox'>
|
|
<div class='HeadlinePub' role='complementary'>
|
|
<script async src='https://pubsrv.devhints.io/carbon.js?serve=CE7IK5QM&placement=devhintsio' id="_carbonads_js"></script>
|
|
<span class='placeholder -one'></span>
|
|
<span class='placeholder -two'></span>
|
|
<span class='placeholder -three'></span>
|
|
<span class='placeholder -four'></span>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class='post-content -cheatsheet'>
|
|
|
|
<h2 id="getting-started">Getting started</h2>
|
|
|
|
<h3 id="hosts">Hosts</h3>
|
|
|
|
<pre><code>$ sudo mkdir /etc/ansible
|
|
$ sudo vim /etc/ansible/hosts
|
|
|
|
[example]
|
|
192.0.2.101
|
|
192.0.2.102
|
|
</code></pre>
|
|
|
|
<h3 id="running-a-playbook">Running a playbook</h3>
|
|
|
|
<pre><code>$ ansible-playbook playbook.yml
|
|
</code></pre>
|
|
|
|
<h2 id="tasks">Tasks</h2>
|
|
|
|
<pre><code>- hosts: all
|
|
user: root
|
|
sudo: no
|
|
vars:
|
|
aaa: bbb
|
|
tasks:
|
|
- ...
|
|
handlers:
|
|
- ...
|
|
</code></pre>
|
|
|
|
<h3 id="includes">Includes</h3>
|
|
|
|
<pre><code>tasks:
|
|
- include: db.yml
|
|
handlers:
|
|
- include: db.yml user=timmy
|
|
</code></pre>
|
|
|
|
<h2 id="handlers">Handlers</h2>
|
|
|
|
<pre><code>handlers:
|
|
- name: start apache2
|
|
action: service name=apache2 state=started
|
|
|
|
tasks:
|
|
- name: install apache
|
|
action: apt pkg=apache2 state=latest
|
|
notify:
|
|
- start apache2
|
|
</code></pre>
|
|
|
|
<h2 id="vars">Vars</h2>
|
|
|
|
<pre><code>- host: lol
|
|
vars_files:
|
|
- vars.yml
|
|
vars:
|
|
project_root: /etc/xyz
|
|
tasks:
|
|
- name: Create the SSH directory.
|
|
file: state=directory path=${project_root}/home/.ssh/
|
|
only_if: "$vm == 0"
|
|
</code></pre>
|
|
|
|
<h2 id="roles">Roles</h2>
|
|
|
|
<pre><code>- host: xxx
|
|
roles:
|
|
- db
|
|
- { role:ruby, sudo_user:$user }
|
|
- web
|
|
|
|
# Uses:
|
|
# roles/db/tasks/*.yml
|
|
# roles/db/handlers/*.yml
|
|
</code></pre>
|
|
|
|
<h3 id="task-failures">Task: Failures</h3>
|
|
|
|
<pre><code>- name: my task
|
|
command: ...
|
|
register: result
|
|
failed_when: "'FAILED' in result.stderr"
|
|
|
|
ignore_errors: yes
|
|
|
|
changed_when: "result.rc != 2"
|
|
</code></pre>
|
|
|
|
<h3 id="env-vars">Env vars</h3>
|
|
|
|
<pre><code>vars:
|
|
local_home: "{{ lookup('env','HOME') }}"
|
|
</code></pre>
|
|
|
|
<h2 id="references">References</h2>
|
|
|
|
<ul>
|
|
<li><a href="http://www.ansibleworks.com/docs/intro_configuration.html">Intro</a></li>
|
|
<li><a href="http://www.ansibleworks.com/docs/modules.html">Modules</a></li>
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<ul class="social-list ">
|
|
<li class="facebook link hint--bottom" data-hint="Share on Facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https://devhints.io/ansible.html" target="share"><span class="text"></span></a></li>
|
|
<li class="twitter link hint--bottom" data-hint="Share on Twitter"><a href="https://twitter.com/intent/tweet?text=The%20ultimate%20cheatsheet%20for%20Ansible.%20https://devhints.io/ansible.html" target="share"><span class="text"></span></a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="about-the-site">
|
|
<div class="container">
|
|
<p class='blurb'>
|
|
<strong><a href=".">Devhints.io cheatsheets</a></strong> is a collection of cheatsheets I've written over the years.
|
|
Suggestions and corrections? <a href='https://github.com/rstacruz/cheatsheets/issues/907'>Send them in</a>.
|
|
<i class='fleuron'></i>
|
|
I'm <a href="http://ricostacruz.com">Rico Sta. Cruz</a>.
|
|
Check out my <a href="http://ricostacruz.com/til">Today I learned blog</a> for more.
|
|
</p>
|
|
|
|
|
|
<p class='back'>
|
|
<a class='big-button -back -slim' href='.#toc'></a>
|
|
</p>
|
|
|
|
|
|
<p>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
|
|
|
|
|
|
|
|
|
|
<script src="https://cdn.rawgit.com/rstacruz/unorphan/v1.0.1/index.js"></script>
|
|
<script>hljs.initHighlightingOnLoad()</script>
|
|
<script>unorphan('h1, h2, h3, p, li, .unorphan')</script>
|
|
|
|
</body>
|
|
</html>
|
|
|