Syntax errors with assert

402 views
Skip to first unread message

Michael Sphar

unread,
Apr 23, 2014, 12:45:42 PM4/23/14
to ansible...@googlegroups.com
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



Matt Martz

unread,
Apr 23, 2014, 12:56:18 PM4/23/14
to Michael Sphar, ansible...@googlegroups.com
You need to indent your 'that' key further:

  tasks:

      - assert:

            that:

                - commonWeekday.stdout == "Saturday"

                - ansible_date_time.hour == "10"

                - commonResultBackup!success

-- 
Matt Martz
ma...@sivel.net
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
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.

Michael Sphar

unread,
Apr 23, 2014, 1:48:22 PM4/23/14
to ansible...@googlegroups.com
(oops, sorry, accidentally replied privately rather than to the group...seriously noobing it up today...)

Hmm...I fixed that, but still getting the same syntax error:  "ERROR: assert is not a legal parameter in an Ansible task or handler"

Michael DeHaan

unread,
Apr 24, 2014, 10:38:25 AM4/24/14
to ansible...@googlegroups.com
This seems very likely a crossed-up install, where your ANSIBLE_LIBRARY path isn't quite set right and you have a new ansible pointing at an old library version.

If running from a checkout, run source ./hacking/env-setup and it will set things up to run from source.




Reply all
Reply to author
Forward
0 new messages