# oddity with command arguments

**URL:** <https://forum.ansible.com/t/oddity-with-command-arguments/28489>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 2, 2018, 1:10am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489 "2018-09-02T01:10:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 2, 2018, 1:10am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/1 "2018-09-02T01:10:30Z")

</div>

I am using the command module to run an AWS CLI command. The command has an argument in it that takes a space-delimited set of parameters, like this:

–subnets-mappings this that theother

When I issue the command on the command line, all the items in the lists are used. When I run the command via Ansible, only the last one in the list is used.

This is how I create the list of subnet mappings:

- set\_fact:  
snm: “{{ snm |default(‘’) ~ ‘SubnetId=’ ~ item.SubnetId ~ ‘,AllocationId=’ ~ item.AllocationId ~ ’ ’ }}”  
with\_items: “{{ nlb\_subnet\_mappings }}”

This is the command I am running:

- command: aws elbv2 create-load-balancer --name “{{ nlb\_name }}” --type network --subnet-mappings “{{ snm }}” --region “{{ nlb\_region }}”  
register: nlb

Here is the “cmd” part returned by the command:

“cmd”: [“aws”, “elbv2”, “create-load-balancer”, “–name”, “ADFS-ext-nlb”, “–type”, “network”, “–subnet-mappings”, "SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 ", “–region”, “ap-southeast-2”]

Because of the way I build the command, there is a space at the end of the list, that is the only difference I can see. And I do build the lists as strings which are then passed as arguments - all the tags are one argument, all the subnets are one argument.

The Ansible command does work and issues no errors, but it only uses the last in the list of subnet mappings. If I do this on the command line, it DOES use both subnet mappings:

aws elbv2 create-load-balancer --name ADFS-ext-nlb --type network --subnet-mappings SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 --region ap-southeast-2

Any clues?

Regards, K.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 2, 2018, 1:54am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/2 "2018-09-02T01:54:14Z")

</div>

It’s even odder than I thought.

The first SubnetID is being paired with the last AllocationID.

These parameters:

"SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 "

…are somehow ending up interpreted as

"SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09c95f8e4f8e111b2 "

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 2, 2018, 2:04am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/3 "2018-09-02T02:04:57Z")

</div>

OK - that was it. Passing all the elements in one string doesn’t work.

So now the big question - is it possible to pass a list of arguments to command and if so how?

Or a more general question, can I turn a list of strings (or output a list of strings) into a list that the command module can use?

Regards, K.

---

<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:** [September 2, 2018, 2:08am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/4 "2018-09-02T02:08:57Z")

</div>

To make it work you need to remove the double quotes in the command module.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 2, 2018, 6:18am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/5 "2018-09-02T06:18:12Z")

</div>

Oh…

After all the thousands of times Ansible has told me I need to wrap Jinja up in quotes, here’s a time I don’t.

Thanks, that simple change solved the issue completely. I did learn a LOT about all sorts of other stuff though, in the hours I have spent trying to work this out 🙂

Regards, K.

---

<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:** [September 2, 2018, 8:24am UTC](https://forum.ansible.com/t/oddity-with-command-arguments/28489/6 "2018-09-02T08:24:44Z")

</div>

> Oh....
> 
> After all the thousands of times Ansible has told me I need to wrap Jinja  
> up in quotes, here's a time I don't.

It is only in one occasion Ansible or more specifically YAML need that.  
And that's when a { comes after a colon, or else YAML will take it as a dictionary.

It has been documented for a long time a go here BTW 🙂  
[https://docs.ansible.com/ansible/latest/reference\_appendices/YAMLSyntax.html#gotchas](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#gotchas)

> Thanks, that simple change solved the issue completely. I did learn a LOT  
> about all sorts of other stuff though, in the hours I have spent trying to  
> work this out 🙂

Problems tends to do that 🙂
