# Using a list variable for efs target key

**URL:** <https://forum.ansible.com/t/using-a-list-variable-for-efs-target-key/25877>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 31, 2017, 3:44pm UTC](https://forum.ansible.com/t/using-a-list-variable-for-efs-target-key/25877 "2017-10-31T15:44:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazzystr](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mazzystr](https://forum.ansible.com/u/mazzystr)\
**Post date:** [October 31, 2017, 3:44pm UTC](https://forum.ansible.com/t/using-a-list-variable-for-efs-target-key/25877/1 "2017-10-31T15:44:53Z")

</div>

Hello,  
Long time listener first time poster here.

AWS Availability Zones are highly dynamic. The Ansible EFS module has a targets key that seems static.

Has anyone been able to push a list variable into this key to get a EFS to deploy in a more dynamic nature?

# ANSIBLE VERSION

$ ansible --version  
ansible 2.3.1.0  
config file = /Users/user/repos/ansible-ops/ansible.cfg  
configured module search path = [u’./library/']  
python version = 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]

# ANSIBLE CODE

- name: Populating targets list  
set\_fact:  
targets: “{{ targets | default() }} + {{ [{ ‘subnet\_id’: efs\_target\_item, ‘security\_groups’: efs\_item.security\_groups }] }}”  
with\_items:

- “{{ efs\_item.subnet }}”  
loop\_control:  
loop\_var: efs\_target\_item

- debug: msg=“{{ targets}}”

- name: Creating EFS Target  
efs:  
aws\_access\_key: “{{ aws\_access\_key }}”  
aws\_secret\_key: “{{ aws\_secret\_key }}”  
security\_token: “{{ security\_token }}”  
state: present  
name: “{{ efs\_item.name }}”  
region: “{{ region }}”  
tags:  
Name: “{{ efs\_item.name }}”  
Site: “{{ site }}”  
targets: [“{{ targets }}”]

#ansible OUTPUT

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/user/repos/ansible-ops/playbooks/roles/aws-efs/tasks/create.yaml:33  
ok: [localhost] =\> {  
“msg”: [  
{  
“security\_groups”: “sg-abcd1234”,  
“subnet\_id”: “subnet-abcd1234”  
},  
{  
“security\_groups”: “sg-abcd1234”,  
“subnet\_id”: “subnet-abcd1234”  
},  
{  
“security\_groups”: “sg-abcd1234”,  
“subnet\_id”: “subnet-abcd1234”  
}  
]  
}

TASK [Create EFS Target] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/user/repos/ansible-ops/playbooks/roles/aws-efs/tasks/create.yaml:35  
Using module file /Users/user/virtualenvs/ansible/lib/python2.7/site-packages/ansible/modules/cloud/amazon/efs.py  
 ESTABLISH LOCAL CONNECTION FOR USER: user  
 EXEC /bin/sh -c ‘echo ~ && sleep 0’  
 EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792`” && echo ansible-tmp-1509464005.83-40924843971792=“`echo /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792`” ) && sleep 0’  
 PUT /var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/tmpsl6C1w TO /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792/efs.py  
 EXEC /bin/sh -c ‘chmod u+x /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792/ /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792/efs.py && sleep 0’  
 EXEC /bin/sh -c ‘python /Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792/efs.py; rm -rf “/Users/user/.ansible/tmp/ansible-tmp-1509464005.83-40924843971792/” \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
Traceback (most recent call last):  
File “/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_1RA7ko/ansible\_module\_efs.py”, line 631, in   
main()  
File “/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_1RA7ko/ansible\_module\_efs.py”, line 599, in main  
targets = [dict((target\_translations[key], value) for (key, value) in x.items()) for x in module.params.get(‘targets’)]  
AttributeError: ‘list’ object has no attribute ‘items’

fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “Traceback (most recent call last):\n File "/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_1RA7ko/ansible\_module\_efs.py", line 631, in \n main()\n File "/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_1RA7ko/ansible\_module\_efs.py", line 599, in main\n targets = [dict((target\_translations[key], value) for (key, value) in x.items()) for x in module.params.get(‘targets’)]\nAttributeError: ‘list’ object has no attribute ‘items’\n”,  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0  
}

Thanks,  
/Chris C

---

<div class="post-metadata">

**Author:** ![mazzystr](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mazzystr](https://forum.ansible.com/u/mazzystr)\
**Post date:** [October 31, 2017, 4:07pm UTC](https://forum.ansible.com/t/using-a-list-variable-for-efs-target-key/25877/2 "2017-10-31T16:07:45Z")

</div>

I solved this problem. Targets security\_groups is a dictionary!

#ansible DEBUG OUTPUT

fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “Traceback (most recent call last):\n File "/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_GOX2SY/ansible\_module\_efs.py", line 631, in \n main()\n File "/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_GOX2SY/ansible\_module\_efs.py", line 614, in main\n changed = connection.converge\_file\_system(name=name, tags=tags, targets=targets) or changed\n File "/var/folders/z\_/kvbxc4110t189p1kg1hky4nm0000gn/T/ansible\_GOX2SY/ansible\_module\_efs.py", line 427, in converge\_file\_system\n \*\*targets[sid]\n File "/Users/ccallega/virtualenvs/ansible/lib/python2.7/site-packages/botocore/client.py", line 312, in \_api\_call\n return self.\_make\_api\_call(operation\_name, kwargs)\n File "/Users/ccallega/virtualenvs/ansible/lib/python2.7/site-packages/botocore/client.py", line 575, in \_make\_api\_call\n api\_params, operation\_model, context=request\_context)\n File "/Users/ccallega/virtualenvs/ansible/lib/python2.7/site-packages/botocore/client.py", line 630, in \_convert\_to\_request\_dict\n api\_params, operation\_model)\n File "/Users/ccallega/virtualenvs/ansible/lib/python2.7/site-packages/botocore/validate.py", line 291, in serialize\_to\_request\n raise ParamValidationError(report=report.generate\_report())\nbotocore.exceptions.ParamValidationError: Parameter validation failed:\nInvalid type for parameter SecurityGroups, value: sg-abcd1234, type: \<type ‘str’\>, valid types: \<type ‘list’\>, \<type ‘tuple’\>\n”,  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0

Here is the working code…

# ANSIBLE CODE

- name: Populating targets list  
set\_fact:  
targets: “{{ targets | default() }} + {{ [{ ‘subnet\_id’: efs\_target\_item, ‘security\_groups’: [ efs\_item.security\_groups] } ] }}”  
with\_items:

- “{{ efs\_item.subnet }}”  
loop\_control:  
loop\_var: efs\_target\_item

- debug: msg=“{{ targets}}”

- name: Creating EFS target  
efs:  
aws\_access\_key: “{{ aws\_access\_key }}”  
aws\_secret\_key: “{{ aws\_secret\_key }}”  
security\_token: “{{ security\_token }}”  
state: present  
name: “{{ efs\_item.name }}”  
region: “{{ region }}”  
tags:  
Name: “{{ efs\_item.name }}”  
Site: “{{ site }}”  
targets: “{{ targets }}”

Thanks,  
/Chris C
