From ebad0d4474289afc278318755031878c85f715db Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 5 May 2013 13:30:26 -0400 Subject: [PATCH] Update conditional examples. --- examples/playbooks/conditionals_part1.yml | 11 +++++----- examples/playbooks/conditionals_part2.yml | 26 ++++++----------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/examples/playbooks/conditionals_part1.yml b/examples/playbooks/conditionals_part1.yml index 87b8350e101..f3f9fcb9a06 100644 --- a/examples/playbooks/conditionals_part1.yml +++ b/examples/playbooks/conditionals_part1.yml @@ -29,10 +29,9 @@ vars_files: - - "vars/external_vars.yml" - - [ "vars/$facter_operatingsystem.yml", "vars/defaults.yml" ] + - [ "vars/{{ facter_operatingsystem }}.yml", "vars/defaults.yml" ] # and this is just a regular task line from a playbook, as we're used to. # but with variables in it that come from above. Note that the variables @@ -41,11 +40,11 @@ tasks: - name: ensure apache is latest - action: $packager pkg=$apache state=latest + action: "{{ packager }} pkg={{ apache }} state=latest" + - name: ensure apache is running - action: service name=$apache state=running - - name: fail - action: command /bin/false + action: service name={{ apache }} state=running + diff --git a/examples/playbooks/conditionals_part2.yml b/examples/playbooks/conditionals_part2.yml index 1bb4a932668..e40a1654a28 100644 --- a/examples/playbooks/conditionals_part2.yml +++ b/examples/playbooks/conditionals_part2.yml @@ -11,44 +11,30 @@ cat: "whiskers" ssn: 8675309 -# These are the types of when statements available -# when_set: $variable_name -# when_unset: $variable_name -# when_str: $x == "test" -# when_int: $y > 2 -# when_float: $z => 2.3 -# -# when using 'when', take care to make sure any variables given are surrounded by spaces -# as an example, $z>3 will not do what you want, use "$z > 3" -# -# note, if you are doing comparisons to variables that are stored as hashes or lists, -# you will need to use the older 'only_if', which is more free form. -# see conditionals_part_3.yml - tasks: - name: "do this if my favcolor is blue, and my dog is named fido" action: shell /bin/false - when_string: $favcolor == 'blue' and $dog == 'fido' + when: favcolor == 'blue' and dog == 'fido' - name: "do this if my favcolor is not blue, and my dog is named fido" action: shell /bin/true - when_string: $favcolor != 'blue' and $dog == 'fido' + when: favcolor != 'blue' and dog == 'fido' - name: "do this if my SSN is over 9000" action: shell /bin/true - when_integer: $ssn > 9000 + when: ssn > 9000 - name: "do this if I have one of these SSNs" action: shell /bin/true - when_integer: $ssn in [ 8675309, 8675310, 8675311 ] + when: ssn in [ 8675309, 8675310, 8675311 ] - name: "do this if a variable named hippo is NOT defined" action: shell /bin/true - when_unset: $hippo + when: hippo is not defined - name: "do this if a variable named hippo is defined" action: shell /bin/true - when_set: $hippo + when: hippo is defined