From f7cff27f3d67cfe7a3b5c001de4d479203c05be2 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 26 Feb 2012 20:54:51 -0500 Subject: [PATCH] Drastically simply playbook syntax --- examples/playbook.yml | 36 +++++++++++------------------------- lib/ansible/playbook.py | 12 +++++++----- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/examples/playbook.yml b/examples/playbook.yml index 70277eca93..d4ff86f90a 100644 --- a/examples/playbook.yml +++ b/examples/playbook.yml @@ -1,33 +1,19 @@ - pattern: '*' hosts: /etc/ansible/hosts tasks: - - do: - - configure template & module variables for future template calls - - setup a=2 b=3 c=4 - - do: - - copy a file from the local disk to the remote - - copy src=/srv/a dest=/srv/b + - name: config step + action: setup a=2 b=3 c=4 + - name: copy comand + action: copy src=/srv/a dest=/srv/b notify: - restart apache - - do: - - template from local file template.j2 to remote location /srv/file.out - - template src=/srv/template.j2 dest=/srv/file.out + - name: template step + action: template src=/srv/template.j2 dest=/srv/file.out notify: - restart apache - - quack like a duck - - do: - - if running as non-root whne you template, you should specify the MD file (1) - - setup a=3 b=4 c=5 metadata=/tmp/metadata.json - - do: - - if running as non-root when you template, you should specify the MD file (2) - - template src=/srv/template.j2 dest=/srv/file2.out metadata=/tmp/metadata.json - - do: - - call something that will fail just to demo failure counts and such - - command /bin/false + - name: execute bin false + comment: call something that will fail just to demo failure counts and such + action: command /bin/false handlers: - - do: - - restart apache - - service name=httpd ensure=restarted - - do: - - quack like a duck - - command /bin/true + - name: restart apache + action: service name=httpd ensure=restarted diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index 8d2bedb512..be4a6420d0 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -113,9 +113,11 @@ class PlayBook(object): # load the module name and parameters from the task # entry - instructions = task['do'] - (comment, module_details) = instructions - tokens = shlex.split(module_details) + name = task['name'] + action = task['action'] + comment = task.get('comment', '') + + tokens = shlex.split(action) module_name = tokens[0] module_args = tokens[1:] @@ -126,9 +128,9 @@ class PlayBook(object): if self.verbose: if not conditional: - print "\nTASK [%s]" % (comment) + print "\nTASK [%s]" % (name) else: - print "\nNOTIFIED [%s]" % (comment) + print "\nNOTIFIED [%s]" % (name) # load up an appropriate ansible runner to # run the task in parallel