2012-03-07 16:35:18 +00: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-12 23:13:19 +00:00
< title > YAML Syntax — Ansible - SSH-Based Configuration Management & Deployment< / title >
2012-03-07 16:35:18 +00:00
< link rel = "stylesheet" href = "_static/default.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/pygments.css" type = "text/css" / >
2012-03-09 16:44:14 +00:00
< link rel = "stylesheet" href = "_static/bootstrap.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/bootstrap-sphinx.css" type = "text/css" / >
2012-03-07 16:35:18 +00:00
< script type = "text/javascript" >
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
2012-03-12 23:13:19 +00:00
VERSION: '0.01',
2012-03-07 16:35:18 +00:00
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
2012-03-09 16:50:07 +00:00
HAS_SOURCE: false
2012-03-07 16:35:18 +00: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 >
2012-03-09 16:44:14 +00:00
< script type = "text/javascript" src = "_static/bootstrap-dropdown.js" > < / script >
< script type = "text/javascript" src = "_static/bootstrap-scrollspy.js" > < / script >
2012-04-01 02:44:02 +00:00
< link rel = "shortcut icon" href = "_static/favicon.ico" / >
2012-03-12 23:13:19 +00:00
< link rel = "top" title = "Ansible - SSH-Based Configuration Management & Deployment" href = "index.html" / >
2012-03-09 16:44:14 +00:00
< 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 03:31:54 +00:00
< / script >
< 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);
})();
2012-03-09 16:44:14 +00:00
< / script >
2012-03-07 16:35:18 +00:00
< / head >
< body >
2012-03-09 16:44:14 +00:00
< div class = "topbar" data-scrollspy = "scrollspy" >
< div class = "topbar-inner" >
< div class = "container" >
< a class = "brand" href = "index.html" > Ansible< / a >
< ul class = "nav" >
< li class = "dropdown" data-dropdown = "dropdown" >
< a href = "index.html"
2012-03-31 13:29:31 +00:00
class="dropdown-toggle">Chapter< / a >
2012-03-09 16:44:14 +00:00
< span class = "globaltoc" > < ul class = "current" >
2012-03-10 02:50:00 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "gettingstarted.html" > Downloads & Getting Started< / a > < / li >
2012-03-09 16:44:14 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "patterns.html" > The Inventory File, Patterns, and Groups< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "examples.html" > Command Line Examples< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "modules.html" > Ansible Modules< / a > < / li >
2012-03-11 19:34:21 +00:00
< li class = "toctree-l1 current" > < a class = "current reference internal" href = "" > YAML Syntax< / a > < / li >
2012-03-09 16:44:14 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "playbooks.html" > Playbooks< / a > < / li >
2012-03-31 02:28:30 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "api.html" > API & Integrations< / a > < / li >
2012-03-14 16:50:40 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "moduledev.html" > Module Development Guide< / a > < / li >
2012-03-10 02:50:00 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "faq.html" > Frequently Asked Questions< / a > < / li >
2012-03-09 16:44:14 +00:00
< / ul >
< / span >
2012-03-31 13:36:37 +00:00
< / 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 >
2012-03-09 16:44:14 +00:00
< / 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 15:39:34 +00:00
2012-03-09 16:44:14 +00:00
< div class = "container" >
2012-03-11 19:34:21 +00:00
< 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 18:36:47 +00:00
< p > This page provides a basic overview of correct YAML syntax, which is how Ansible
2012-03-11 19:34:21 +00:00
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 21:16:31 +00: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
2012-03-11 19:34:21 +00:00
is used in practice.< / p >
2012-03-07 16:35:18 +00:00
< div class = "section" id = "yaml-basics" >
< h2 > YAML Basics< a class = "headerlink" href = "#yaml-basics" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-14 00:32:55 +00:00
< 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
2012-03-11 19:34:21 +00:00
called a “ hash” or a “ dictionary” . So, we need to know how
to write lists and dictionaries in YAML.< / p >
< p > There’ 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 “ this is the start of a document” .< / 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 16:35:18 +00: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 >
2012-03-11 19:34:21 +00:00
< p > Dictionaries can also be represented in an abbreviated form if you really want to:< / p >
2012-03-07 16:35:18 +00:00
< div class = "highlight-python" > < pre > ---
# An employee record
{name: John Eckersberg, job: Developer, skill: Elite}< / pre >
< / div >
2012-03-11 19:34:21 +00:00
< p id = "truthiness" > Ansible doesn’ t really use these too much, but you can also specify a
boolean value (true/false) in several forms:< / p >
2012-03-07 16:35:18 +00:00
< div class = "highlight-python" > < pre > ---
knows_oop: True
likes_emacs: TRUE
uses_cvs: false< / pre >
< / div >
2012-03-11 19:34:21 +00:00
< p > Let’ 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 16:35:18 +00: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’ s all you really need to know about YAML to get started writing
2012-03-08 18:36:47 +00:00
< cite > Ansible< / cite > playbooks.< / p >
2012-03-07 16:35:18 +00:00
< div class = "admonition-see-also admonition seealso" >
< p class = "first admonition-title" > See also< / p >
< dl class = "last docutils" >
2012-03-11 19:34:21 +00:00
< 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 16:35:18 +00:00
< dt > < a class = "reference external" href = "http://yamllint.com/" > YAMLLint< / a > < / dt >
2012-03-11 19:34:21 +00:00
< dd > YAML Lint (online) helps you debug YAML syntax if you are having problems< / dd >
2012-03-31 13:29:31 +00:00
< dt > < a class = "reference external" href = "https://github.com/ansible/ansible/tree/master/examples/playbooks" > Github examples directory< / a > < / dt >
< dd > Complete playbook files from the github project source< / dd >
2012-03-31 13:55:37 +00:00
< 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 16:35:18 +00:00
< / dl >
< / div >
< / div >
< / div >
< / div >
2012-03-09 16:44:14 +00:00
< footer class = "footer" >
< div class = "container" >
< p class = "pull-right" > < a href = "#" > Back to top< / a > < / p >
< p >
© Copyright 2012 Michael DeHaan.< br / >
2012-04-17 23:54:23 +00:00
Last updated on Apr 17, 2012.< br / >
2012-03-26 23:48:32 +00:00
Created using < a href = "http://sphinx.pocoo.org/" > Sphinx< / a > 1.0.8.< br / >
2012-03-09 16:44:14 +00:00
< / p >
< / div >
< / footer >
2012-03-07 16:35:18 +00:00
< / body >
< / html >