Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.
@FlorianHeigl

This comment has been minimized.

Copy link

@FlorianHeigl FlorianHeigl commented Jan 18, 2013

And THAT is how you make nice things!

@vmalloc

This comment has been minimized.

Copy link

@vmalloc vmalloc commented Feb 11, 2013

Just note that the per-action user doesn't work. Ansible complains that multiple actions are defined for that item..

@dagwieers

This comment has been minimized.

Copy link

@dagwieers dagwieers commented Apr 5, 2013

@vmalloc Yes, welcome to conflicting namespaces ! Ever since we allowed to ommit 'action:' and directly do 'module:' we risk having more than one action, or worse conflicting keywords.

@SamHughes

This comment has been minimized.

Copy link

@SamHughes SamHughes commented Apr 26, 2013

LOVE This. Thank you so much.

@mpdehaan

This comment has been minimized.

Copy link

@mpdehaan mpdehaan commented May 17, 2013

I just wanted to mention to everyone that this, while great at the time, is now pretty old.

It doesn't show roles and a lot of features in 1.2, and still uses the "only_if" syntax, which is now made easier by "when". In addition, variable substitution is also in many ways improved.

While things remain compatible, these are not the best ways to do everything in all cases. (Many things remain unchanged, of course), nor does it show everything.

I would suggest reading the latest documentation at http://ansible.cc/docs and then also looking at the "ansible-examples repo: https://github.com/ansible/ansible-examples

Which shows various things put into context.

@fiterbek

This comment has been minimized.

Copy link

@fiterbek fiterbek commented May 23, 2013

mpdehaan is right. For example, the example above (line 50 and following) states ',' as separator when using multiple groups in a hosts declaration, while http://ansible.cc/docs/patterns.html#selecting-targets shows ':' . The latter is correct, took me some time to figure it out.

But still my respect for this of course! It's helped me a lot getting to know all of ansible's possibilities!

@pfalcon

This comment has been minimized.

Copy link

@pfalcon pfalcon commented Jul 13, 2013

Other misguiding info in this example:

# Notice the minus on the line below -- this starts the playbook's record
# in the YAML document. Only one playbook is allowed per YAML file.  Indent
# the body of the playbook.
- hosts: all

So, only one playbook is allowed per YAML file, actually, such YAML file is a playbook. But playbook consists of one or more of "plays", and "hosts:" line marks beginning of a play, there can be multiple, each applying to a different (or even to same!) set of hosts.

@jimrybarski

This comment has been minimized.

Copy link

@jimrybarski jimrybarski commented Sep 21, 2013

Shouldn't this say ${web.httpd} instead of ${web.apache} ?

# For this example, ${web.memcache} and ${web.apache} are both usable
# variables.
@mpdehaan

This comment has been minimized.

Copy link

@mpdehaan mpdehaan commented Jan 27, 2014

At this point in time ${foo} variables are deprecated and slated for removal in 1.6.

Operators with "when_foo" are also completely removed as of 1.5 in favor of the simplified when, and there is no "only_if" operation.

While I'm very happy this was created, folks should refer to docs.ansible.com instead at this time.

@ranjib

This comment has been minimized.

Copy link

@ranjib ranjib commented Feb 1, 2014

this is awesome!

@mpdehaan

This comment has been minimized.

Copy link

@mpdehaan mpdehaan commented Apr 23, 2014

1.6 is due for release in about a week.

At this point, I should also mention a lot of things like do/until are not shown here.

$foo variables no longer are also no longer valid syntax in 1.6 (devel branch, releasing very soon)

Please consult http://docs.ansible.com/ for all the latest

@jtyr

This comment has been minimized.

Copy link

@jtyr jtyr commented Nov 30, 2014

This Gist is very useful and I wish the author keeps it up-to-date. If somebody already tried to update it, please place your Gist link here.

@chacham15

This comment has been minimized.

Copy link

@chacham15 chacham15 commented Jan 4, 2015

@mpdehaan while this may be out of date it is still way more informative for the beginner than any of the official examples or docs. Take one of the examples in your example directory: https://github.com/ansible/ansible-examples/blob/master/wordpress-nginx/roles/nginx/tasks/main.yml what does this tell someone like me who just picked up ansible?

@nfarrar

This comment has been minimized.

Copy link

@nfarrar nfarrar commented Jan 30, 2015

Wicked useful, thank you!

@FractalizeR

This comment has been minimized.

Copy link

@FractalizeR FractalizeR commented May 2, 2015

An insanely great job ;)

@yonassrobi

This comment has been minimized.

Copy link

@yonassrobi yonassrobi commented Sep 1, 2015

Nice collection!

@thomo

This comment has been minimized.

Copy link

@thomo thomo commented Sep 20, 2015

I just started to learn ansible but would suggest the following modifications:

  • line 83:
    • org

      user: remoteuser
      
    • new

      remote_user: remoteuser
      ### The remote_user parameter was formerly called just user. It was renamed in Ansible 1.4 to make it more distinguishable from the user module (used to create users on remote systems).
      
  • line 107:
    • org

       # For this example, ${web.memcache} and ${web.apache} are both usable
      
    • new

      # For this example, ${web.memcache} and ${web.httpd} are both usable
      
@sudhevan

This comment has been minimized.

Copy link

@sudhevan sudhevan commented Oct 17, 2015

hi,
is there a way to specify the become user is handlers part?

handlers:

  • name: restart apache
    service: name=apache state=restarted
    become=yes
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 14, 2016

I know this is out of date... but I'm going to say it anyways as an FYI-- in Line 433 you can no longer include handlers as of Ansible 2.0

@derek-adair

This comment has been minimized.

Copy link

@derek-adair derek-adair commented Apr 11, 2016

This would be really cool to evolve and keep up to date to showcase a detailed changelog.

@shiplu

This comment has been minimized.

Copy link

@shiplu shiplu commented Apr 12, 2016

Great Playbook. A lot of things are clear to me now.

@gretel

This comment has been minimized.

Copy link

@gretel gretel commented May 4, 2016

should be part of the core documentation. thanks!

@SayBeano

This comment has been minimized.

Copy link

@SayBeano SayBeano commented May 23, 2016

Amazing!

edit: And thanks, @marktheunissen!

@henryxn

This comment has been minimized.

Copy link

@henryxn henryxn commented May 26, 2016

In term of using variable in hosts attribute (line 58)
ORIG:

hosts: $groups -- apply to all hosts specified in the variable $groups

REVISE:
hosts : group # No $

$ ansible-playbook playbook1.yml -e "group=myservers"
or
$ ansible-playbook playbook1.yml --extra-vars="target=myservers"

@akofink

This comment has been minimized.

Copy link

@akofink akofink commented Jul 26, 2016

sudo: true is deprecated in favor of become: true

source: http://docs.ansible.com/ansible/become.html

@antoniopinarella

This comment has been minimized.

Copy link

@antoniopinarella antoniopinarella commented Feb 10, 2017

which editor u use for yaml?

@claudiols1979

This comment has been minimized.

Copy link

@claudiols1979 claudiols1979 commented Mar 14, 2017

@antoniopinarella you can use any text editor. I use vim for .yml and it works fine.
(Probably you found it out. However for new people searches. )

@flamein

This comment has been minimized.

Copy link

@flamein flamein commented Mar 9, 2018

Can we please bury this Gist? it keeps showing up as clickbait in search engines while the syntax is horribly outdated.

@dataf3l

This comment has been minimized.

Copy link

@dataf3l dataf3l commented Sep 25, 2019

I love this, please include "become"

@ogratwicklcs

This comment has been minimized.

Copy link

@ogratwicklcs ogratwicklcs commented Jan 21, 2020

I have made a fork and updated some of the content that has been deprecated.
https://gist.github.com/ogratwicklcs/b9765a5b053b46586b4eb7fe61a15c82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.