From d3fe5f617a4707cc8de00c996739d979fd656a78 Mon Sep 17 00:00:00 2001
From: Michael DeHaan This page provides a basic overview of correct YAML syntax, which is how Ansible
-playbooks (our configuration management language) are expressed.
-You may also wish to read playbook examples and will quickly pick this up from those. 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. You may also wish to read playbook examples at the same time to see how this
+is used in practice. See also For ansible, every YAML file must be a list at it’s root-most
-element. Each item in the list is a dictionary. These dictionaries
-represent all the options you can use to write an ansible file. In
-addition, all YAML files (regardless of their association with
-ansible or not) should start with ---. In YAML a list can be represented in two ways. In one way all members
-of a list are lines beginning at the same indentation level starting
-with a - character: For ansible, every YAML file starts with a list of things
+to do. Each item in the list is a list of key/value pairs, commonly
+called a “hash” or a “dictionary”. So, we need to know how
+to write lists and dictionaries in YAML. There’s another small quirk to YAML. All YAML files (regardless of their association with
+ansible or not) should start with ---. This is just a YAML
+format thing that means “this is the start of a document”. All members of a list are lines beginning at the same indentation level starting
+with a - (dash) character: In the second way a list is represented as comma separated elements
-surrounded by square brackets. Newlines are permitted between
-elements: A dictionary is represented in a simple key: and value form: Like lists, dictionaries can be represented in an abbreviated form: Dictionaries can also be represented in an abbreviated form if you really want to: You can specify a boolean value (true/false) in several forms: Ansible doesn’t really use these too much, but you can also specify a
+boolean value (true/false) in several forms: Finally, you can combine these data structures: 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:
© Copyright 2012 Michael DeHaan.
© Copyright 2012 Michael DeHaan.
© Copyright 2012 Michael DeHaan. It also excels for writing distributed
scripts and ad-hoc applications that need to gather data or perform arbitrary
tasks – whether for a QA sytem, build system, or anything you can think of. See also
© Copyright 2012 Michael DeHaan.
© Copyright 2012 Michael DeHaan. Congratulations. You’ve just contacted your nodes with Ansible. It’s
-now time to read some of the more real-world examples, and explore
+now time to read some of the more real-world Command Line Examples, and explore
what you can do with different modules, as well as the Ansible
-playbooks language. Ansible is not just about running commands, but
+Playbooks language. Ansible is not just about running commands, but
you already have a working infrastructure! See also
-
+
YAML Format¶
+ YAML Syntax¶
+
+YAML Basics¶
----
# A list of tasty fruits
- Apple
@@ -190,13 +202,6 @@ with a - character:
- Strawberry
- Mango
---
-# A list of tasty fruits
-[apple, orange, banana, mango]
----
# An employee record
@@ -204,18 +209,20 @@ name: John Eckersberg
job: Developer
skill: Elite
---
# An employee record
{name: John Eckersberg, job: Developer, skill: Elite}
---
knows_oop: True
likes_emacs: TRUE
uses_cvs: false
---
# An employee record
name: John Eckersberg
@@ -237,8 +244,10 @@ languages:
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
+
+
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
ansible all /bin/echo hello
-
© Copyright 2012 Michael DeHaan.
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.
© Copyright 2012 Michael DeHaan.
- Last updated on Mar 10, 2012.
+ Last updated on Mar 11, 2012.
Created using Sphinx 1.0.8.