We are upgrading from ansible 2.1.0 to 2.2.2.0 and our syntax validation tests are failing on the ec2_facts module. Syntax for using ec2_facts has changed.
To test syntax, we use: ansible-playbook --syntax-check --list-tasks -i localhost .yml
Up to version 2.2.1.0 the following play would validate:
- name: Gather ec2 metadata
action: ec2_facts
As of 2.2.2.0 this play now returns the following error:
ERROR! ‘action’ is not a valid attribute for a Play
The error appears to have been in ‘test-play.yml’: line 2, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Gather ec2 metadata
^ here
In 2.2.2.0 the following play will validate:
- name: Gather ec2 metadata
ec2_facts:
During the transition we need to support both sets of syntax. How can I conditionally include the pre-2.2.2.0 syntax for lower version environments and 2.2.2.0 syntax for newer environments?
My first unsuccessful attempt was the following:
- name: Gather ec2 metadata
action: ec2_facts
when: ansible_version < 2.2.2.0
- name: Gather ec2 metadata
ec2_facts:
when: ansible_version >= 2.2.2.0
Any thoughts on version conditional syntax are much appreciated.
Thanks,
Thad
We are upgrading from ansible 2.1.0 to 2.2.2.0 and our syntax validation
tests are failing on the ec2_facts module. Syntax for using ec2_facts has
changed.
It hasn't.
To test syntax, we use: ansible-playbook --syntax-check --list-tasks -i
localhost <playbook>.yml
Up to version 2.2.1.0 the following play would validate:
- name: Gather ec2 metadata
action: ec2_facts
As of 2.2.2.0 this play now returns the following error:
ERROR! 'action' is not a valid attribute for a Play
The error appears to have been in 'test-play.yml': line 2, column 5, but
may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Gather ec2 metadata
^ here
In 2.2.2.0 the following play will validate:
- name: Gather ec2 metadata
ec2_facts:
The action: directive is not part of the ec2_facts module syntax, but Ansible itself.
Using action: has not been recommended/preferred since Ansible 0.8
https://docs.ansible.com/ansible/playbooks_intro.html#action-shorthand
That being said, you error indicate missing tasks: or a indention error.
One example on indention error that trigger the same error message.
- hosts: localhost
tasks:
- name: Test
action: debug msg="test"
During the transition we need to support both sets of syntax. How can I
conditionally include the pre-2.2.2.0 syntax for lower version environments
and 2.2.2.0 syntax for newer environments?
Why, since that syntax is supported since Ansible 0.8?