# Ansible 2.1.0 to 2.2.2.0 ec2\_facts change

**URL:** <https://forum.ansible.com/t/ansible-2-1-0-to-2-2-2-0-ec2-facts-change/24156>\
**Category:** Ansible Project\
**Created:** [April 6, 2017, 9:06am UTC](https://forum.ansible.com/t/ansible-2-1-0-to-2-2-2-0-ec2-facts-change/24156 "2017-04-06T09:06:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thad\_Scalf](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@Thad\_Scalf](https://forum.ansible.com/u/Thad_Scalf)\
**Post date:** [April 6, 2017, 9:06am UTC](https://forum.ansible.com/t/ansible-2-1-0-to-2-2-2-0-ec2-facts-change/24156/1 "2017-04-06T09:06:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 6, 2017, 5:59pm UTC](https://forum.ansible.com/t/ansible-2-1-0-to-2-2-2-0-ec2-facts-change/24156/2 "2017-04-06T17:59:18Z")

</div>

> 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:
> 
> > &nbsp;&nbsp;- name: Gather ec2 metadata  
> > &nbsp;&nbsp;&nbsp;&nbsp;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:  
> > ---  
> > &nbsp;&nbsp;- name: Gather ec2 metadata  
> > &nbsp;&nbsp;&nbsp;&nbsp;^ here
> 
> In 2.2.2.0 the following play will validate:
> 
> > &nbsp;&nbsp;- name: Gather ec2 metadata  
> > &nbsp;&nbsp;&nbsp;&nbsp;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](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  
&nbsp;&nbsp;&nbsp;tasks:  
- name: Test  
&nbsp;&nbsp;&nbsp;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?
