# Module argument syntax styles?

**URL:** <https://forum.ansible.com/t/module-argument-syntax-styles/15775>\
**Category:** Ansible Project\
**Created:** [July 25, 2014, 7:24am UTC](https://forum.ansible.com/t/module-argument-syntax-styles/15775 "2014-07-25T07:24:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steffen\_Prince](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Steffen\_Prince](https://forum.ansible.com/u/Steffen_Prince)\
**Post date:** [July 25, 2014, 7:24am UTC](https://forum.ansible.com/t/module-argument-syntax-styles/15775/1 "2014-07-25T07:24:19Z")

</div>

Pros and cons of module argument syntax styles?

INI style

`

- module: \>  
key1=val1  
key2=val2  
key3=val3  
key4=val4  
`

yaml style

`

- module:  
key1: val1  
key2: val2  
key3: val3  
key4: val4  
`

Real world examples here: [https://gist.github.com/sprin/fc0ddcdfa330aa93facc](https://gist.github.com/sprin/fc0ddcdfa330aa93facc)

With both styles, we can get one keyword/value pair per line, which is very  
fast to scan and good for diffs.

The yaml style requires you to quote templated-in params, which makes them  
stand out nicely with highlighting. Other than that, the two syntaxes are  
functionally equivalent, no?

The INI style allows one-liners, but…

Let’s be honest, this is terrible to read, bad for diffs, and we should  
avoid it:

`

- module: key1=val1 key2=val2 key3=val key4=val4

`

I suspect this may have been discussed before, but a search on this group  
turned up nothing. Apologies if this has already been discussed!

Aside:

The more I work with Ansible syntax, the more I appreciate it’s key strength  
is how clean and quick to read it is. Simple, concise, self-documenting  
infrastructure… config has come out of the dark ages.

Nod to puppet/chef for getting things rolling in the right direction, but omg,  
what a syntactical abomination puppet is. and chef cookbooks always end up  
a laughable tangle of poorly written ruby.

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [July 25, 2014, 1:25pm UTC](https://forum.ansible.com/t/module-argument-syntax-styles/15775/2 "2014-07-25T13:25:04Z")

</div>

Excerpts from Steffen Prince's message of 2014-07-25 03:24:19 -0400:

> Pros and cons of module argument syntax styles?
> 
> INI style
> 
> - module: \>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key1=val1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key2=val2  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key3=val3  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key4=val4
> 
> yaml style
> 
> - module:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key1: val1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key2: val2  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key3: val3  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key4: val4

Personally, I strongly prefer the latter.

I don't think that a general case can be made for one or the other,  
though --- just preference.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 25, 2014, 1:30pm UTC](https://forum.ansible.com/t/module-argument-syntax-styles/15775/3 "2014-07-25T13:30:07Z")

</div>

The idea behind key=value is it makes it nice to put everything all on one line.

yum: name=foo state=installed

Which leads to more concise playbooks than the short-form YAML style

yum: { name: ‘foo’, state: ‘installed’ }

And is easier to type and skim.

We don’t care which way you do things, though if you are going to put things on seperate lines and use the long form, it makes sense to use the YAML data structure.

We’ll continue to use the short form for most everything until lines get long, or complicated structured data needs to be passed (like the cloud modules).

---

<div class="post-metadata">

**Author:** ![Steffen\_Prince](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Steffen\_Prince](https://forum.ansible.com/u/Steffen_Prince)\
**Post date:** [July 25, 2014, 5:56pm UTC](https://forum.ansible.com/t/module-argument-syntax-styles/15775/4 "2014-07-25T17:56:22Z")

</div>

Thanks, makes perfect sense why the two syntaxes are available. I think I’ll be  
sticking to the long form to keep it simple and consistent for new people.
