1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/docsite/YAMLSyntax.html

276 lines
10 KiB
HTML
Raw Normal View History

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">
2012-08-31 00:41:19 +02:00
2012-03-07 17:35:18 +01:00
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>YAML Syntax &mdash; Ansible Documentation</title>
2012-08-31 00:41:19 +02:00
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" />
<link rel="stylesheet" href="_static/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
2012-08-31 00:41:19 +02:00
2012-03-07 17:35:18 +01:00
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.01',
2012-03-07 17:35:18 +01:00
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
2012-03-09 17:50:07 +01:00
HAS_SOURCE: false
2012-03-07 17:35:18 +01:00
};
</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>
<script type="text/javascript" src="_static/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="_static/bootstrap-scrollspy.js"></script>
2012-04-01 04:44:02 +02:00
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="top" title="Ansible Documentation" href="index.html" />
<link rel="next" title="Playbooks" href="playbooks.html" />
<link rel="prev" title="Ansible Modules" href="modules.html" />
<script type="text/javascript">
(function () {
/**
* Patch TOC list.
*
* Will mutate the underlying span to have a correct ul for nav.
*
* @param $span: Span containing nested UL's to mutate.
* @param minLevel: Starting level for nested lists. (1: global, 2: local).
*/
var patchToc = function ($span, minLevel) {
var $tocList = $("<ul/>").attr('class', "dropdown-menu"),
findA;
// Find all a "internal" tags, traversing recursively.
findA = function ($elem, level) {
var level = level || 0,
$items = $elem.find("> li > a.internal, > ul, > li > ul");
// Iterate everything in order.
$items.each(function (index, item) {
var $item = $(item),
tag = item.tagName.toLowerCase(),
pad = 10 + ((level - minLevel) * 10);
if (tag === 'a' && level >= minLevel) {
// Add to existing padding.
$item.css('padding-left', pad + "px");
// Add list element.
$tocList.append($("<li/>").append($item));
} else if (tag === 'ul') {
// Recurse.
findA($item, level + 1);
}
});
};
// Start construction and return.
findA($span);
// Wipe out old list and patch in new one.
return $span.empty("ul").append($tocList);
};
$(document).ready(function () {
// Patch the global and local TOC's to be bootstrap-compliant.
patchToc($("span.globaltoc"), 1);
patchToc($("span.localtoc"), 2);
// Activate.
$('#topbar').dropdown();
});
}());
2012-03-10 04:31:54 +01:00
</script>
2012-03-10 04:31:54 +01:00
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29861888-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type =
'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
2012-04-28 16:42:32 +02:00
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
2012-03-07 17:35:18 +01:00
</head>
<body>
<div class="topbar" data-scrollspy="scrollspy" >
<div class="topbar-inner">
<div class="container">
<a class="brand" href="index.html">Ansible Documentation</a>
<ul class="nav">
<li><a href="/">Home</A>
<li class="dropdown" data-dropdown="dropdown">
<a href="index.html"
class="dropdown-toggle">Chapter</a>
<span class="globaltoc"><ul class="current">
2012-05-13 17:00:02 +02:00
<li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="patterns.html">Inventory &amp; Patterns</a></li>
2012-08-17 03:12:36 +02:00
<li class="toctree-l1"><a class="reference internal" href="examples.html">Command Line Examples And Next Steps</a></li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Ansible Modules</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">YAML Syntax</a></li>
<li class="toctree-l1"><a class="reference internal" href="playbooks.html">Playbooks</a></li>
2012-05-13 17:00:02 +02:00
<li class="toctree-l1"><a class="reference internal" href="playbooks2.html">Advanced Playbooks</a></li>
<li class="toctree-l1"><a class="reference internal" href="bestpractices.html">Best Practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">API &amp; Integrations</a></li>
2012-05-13 17:00:02 +02:00
<li class="toctree-l1"><a class="reference internal" href="moduledev.html">Module Development</a></li>
</ul>
</span>
</li>
<li class="dropdown" data-dropdown="dropdown">
<a href="#"
class="dropdown-toggle">Page</a>
<span class="localtoc"><ul>
<li><a class="reference internal" href="#">YAML Syntax</a><ul>
<li><a class="reference internal" href="#yaml-basics">YAML Basics</a></li>
</ul>
</li>
</ul>
</span>
</li>
</ul>
<ul class="nav secondary-nav">
<form class="pull-left" action="search.html" method="get">
<input type="text" name="q" placeholder="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</ul>
</div>
</div>
</div>
2012-03-10 16:39:34 +01:00
<div class="container">
<div class="section" id="yaml-syntax">
<h1>YAML Syntax<a class="headerlink" href="#yaml-syntax" title="Permalink to this headline"></a></h1>
2012-03-08 19:36:47 +01:00
<p>This page provides a basic overview of correct YAML syntax, which is how Ansible
playbooks (our configuration management language) are expressed.</p>
<p>We use YAML because it is easier to read and write for humans than other common
data formats like XML or JSON. Further, there are libraries available for reading
and writing YAML in most programming languages.</p>
2012-03-17 22:16:31 +01:00
<p>You may also wish to read <a class="reference internal" href="playbooks.html"><em>Playbooks</em></a> at the same time to see how this
is used in practice.</p>
2012-03-07 17:35:18 +01:00
<div class="section" id="yaml-basics">
<h2>YAML Basics<a class="headerlink" href="#yaml-basics" title="Permalink to this headline"></a></h2>
<p>For <cite>ansible</cite>, nearly every YAML file starts with a list.
Each item in the list is a list of key/value pairs, commonly
called a &#8220;hash&#8221; or a &#8220;dictionary&#8221;. So, we need to know how
to write lists and dictionaries in YAML.</p>
<p>There&#8217;s another small quirk to YAML. All YAML files (regardless of their association with
<cite>ansible</cite> or not) should start with <tt class="docutils literal"><span class="pre">---</span></tt>. This is just a YAML
format thing that means &#8220;this is the start of a document&#8221;.</p>
<p>All members of a list are lines beginning at the same indentation level starting
with a <tt class="docutils literal"><span class="pre">-</span></tt> (dash) character:</p>
2012-03-07 17:35:18 +01:00
<div class="highlight-python"><pre>---
# A list of tasty fruits
- Apple
- Orange
- Strawberry
- Mango</pre>
</div>
<p>A dictionary is represented in a simple <tt class="docutils literal"><span class="pre">key:</span></tt> and <tt class="docutils literal"><span class="pre">value</span></tt> form:</p>
<div class="highlight-python"><pre>---
# An employee record
name: John Eckersberg
job: Developer
skill: Elite</pre>
</div>
<p>Dictionaries can also be represented in an abbreviated form if you really want to:</p>
2012-03-07 17:35:18 +01:00
<div class="highlight-python"><pre>---
# An employee record
{name: John Eckersberg, job: Developer, skill: Elite}</pre>
</div>
<p id="truthiness">Ansible doesn&#8217;t really use these too much, but you can also specify a
boolean value (true/false) in several forms:</p>
2012-03-07 17:35:18 +01:00
<div class="highlight-python"><pre>---
knows_oop: True
likes_emacs: TRUE
uses_cvs: false</pre>
</div>
<p>Let&#8217;s combine what we learned so far in an arbitary YAML example. This really
has nothing to do with Ansible, but will give you a feel for the format:</p>
2012-03-07 17:35:18 +01:00
<div class="highlight-python"><pre>---
# An employee record
name: John Eckersberg
job: Developer
skill: Elite
employed: True
foods:
- Apple
- Orange
- Strawberry
- Mango
languages:
ruby: Elite
python: Elite
dotnet: Lame</pre>
</div>
<p>That&#8217;s all you really need to know about YAML to get started writing
2012-03-08 19:36:47 +01:00
<cite>Ansible</cite> playbooks.</p>
2012-03-07 17:35:18 +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="playbooks.html"><em>Playbooks</em></a></dt>
<dd>Learn what playbooks can do and how to write/run them.</dd>
2012-03-07 17:35:18 +01:00
<dt><a class="reference external" href="http://yamllint.com/">YAMLLint</a></dt>
<dd>YAML Lint (online) helps you debug YAML syntax if you are having problems</dd>
<dt><a class="reference external" href="https://github.com/ansible/ansible/tree/devel/examples/playbooks">Github examples directory</a></dt>
<dd>Complete playbook files from the github project source</dd>
<dt><a class="reference external" href="http://groups.google.com/group/ansible-project">Mailing List</a></dt>
<dd>Questions? Help? Ideas? Stop by the list on Google Groups</dd>
<dt><a class="reference external" href="http://irc.freenode.net">irc.freenode.net</a></dt>
<dd>#ansible IRC chat channel</dd>
2012-03-07 17:35:18 +01:00
</dl>
</div>
</div>
</div>
2012-04-28 16:42:32 +02:00
<br/>
2012-03-07 17:35:18 +01:00
</div>
2012-04-28 16:53:15 +02:00
<footer class="footer">
<div class="container">
2012-07-31 02:08:13 +02:00
<p>
2012-04-28 16:50:20 +02:00
<p>
&copy; Copyright 2012 Michael DeHaan.<br/>
2012-10-08 13:39:06 +02:00
Last updated on Oct 08, 2012.<br/>
</p>
</div>
</footer>
2012-03-07 17:35:18 +01:00
</body>
</html>