You need to indent your 'that' key further:

  tasks:

      - assert:

            that:

                - commonWeekday.stdout == "Saturday"

                - ansible_date_time.hour == "10"

                - commonResultBackup!success

-- 
Matt Martz
[email protected]

On April 23, 2014 at 11:54:34 AM, Michael Sphar ([email protected]) wrote:

I'm still pretty new to ansible, so I feel like I am probably doing something 
really stupid, but I cannot get the assert module to work.  

I have ansible version 1.5.3.  I'm getting "ERROR: assert is not a legal 
parameter in an Ansible task or handler" in all my attempts to use an assert.  
I've been searching the docs and all I can find is the doc which gives a 
snippet example of using assert and my attempts to copy that aren't working, 
and I can't find an actual complete playbook example that includes the use of 
assert to compare to.

What I'm trying to do, assert may not even be the right approach for.  
Basically I'm developing a playbook for automated reboots that is *very* 
dangerous during production hours and which should only ever be allowed to run 
on a Saturday during a designated window, and so I want the playbook to include 
some explicit rules that will prevent it from rebooting when it's not supposed 
to, even if some chucklehead accidentally executes it during the week.

Ideally, I'd be able just reference an ansible fact for the day of the week, 
but I can't seem to find one? So I'm using the date command to get the day of 
the week and registering that into a variable.  Then I want to abort the 
playbook when that and another condition are not met.

My test playbook looks like this (the tasks that set commonWeekday and 
commonResultBackup are in roles/common/tasks/main.yml):

REBOOTGROUP_SAT_10AM.yml:

---

- hosts: REBOOTGROUP_SAT_10AM

  roles:

    - common



  tasks:

    - assert:

      that:

        - commonWeekday.stdout == "Saturday"

        - ansible_date_time.hour == "10"

        - commonResultBackup!success



    - name:  Reboot the server with warning delay - Don't wait for it to 
complete

      command: shutdown -r +5 Automated Weekly Reboot

      sudo: yes

      async: 600

      poll: 0

      ignore_errors: true



And if I test it:



$ ansible-playbook --syntax-check REBOOTGROUP_SAT_10AM.yml 

playbook: REBOOTGROUP_SAT_10AM.yml

ERROR: assert is not a legal parameter in an Ansible task or handler





--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/895b2035-523d-4e2f-a0de-e4e447f11ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/etPan.5357f0b2.6b8b4567.9c54%40mobiletuvix.rackspace.corp.
For more options, visit https://groups.google.com/d/optout.

Reply via email to