Syntax for providing module parameters

29 views
Skip to first unread message

Jim McMahon

unread,
Feb 7, 2015, 9:11:15 AM2/7/15
to ansible...@googlegroups.com
Many examples of tasks I see give module parameters with key=value syntax like this:


- name: add update-motd package
  sudo: yes
  yum: 
    name=update-motd
    state=present
  tags: 
    - motd

- name: install figlet for banner messages with pizazz
  sudo: yes
  yum: 
    name=figlet
    state=present
  tags: 
    - motd

---

But I've also found that I can use colons to separate the key/value pairs for the module too.  Like this:

- name: add update-motd package
  sudo: yes
  yum: 
    name: update-motd
    state: present
  tags: 
    - motd

- name: install figlet for banner messages with pizazz
  sudo: yes
  yum: 
    name: figlet
    state: present
  tags: 
    - motd

Is the second way wrong?  Is one way preferred over the other?


Serge van Ginderachter

unread,
Feb 7, 2015, 9:13:43 AM2/7/15
to ansible...@googlegroups.com

On 7 February 2015 at 15:11, Jim McMahon <jmcm...@flatworldknowledge.com> wrote:
Is the second way wrong?  Is one way preferred over the other?

​Definitely not wrong.​

​Personally, I prefer the second., which is more pure yamlish.

Jim McMahon

unread,
Feb 7, 2015, 9:18:38 AM2/7/15
to ansible...@googlegroups.com
This is good to know, thanks.  I kind of discovered the second syntax when studying Yaml.  But most of the examples I see on the Ansible pages use name=value, which made me wonder if the name: value style was not appropriate.


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/ZXRRDvGNl8Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEhzMJB6vKWN8toAtT-gWdez05cNf6JygdfrqNwzarT8K0Deew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Feb 7, 2015, 10:10:53 AM2/7/15
to ansible...@googlegroups.com

Both syntaxes are valid, you see more of the key=value in the docs because it is more concise (1 line). When the module requires many arguments we tend to switch (check the cloud guides).

The truth is that the yaml syntax might be better as it avoids an extra parser.

Reply all
Reply to author
Forward
0 new messages