Module Parameter Defaults (or Module Shortcut/Alias) ?

36 views
Skip to first unread message

dennis.b...@sap.com

unread,
Nov 17, 2015, 10:46:10 AM11/17/15
to Ansible Project
Hello List,

is it possible to set defaults for the parameters of a module? Or create a shortcut/alias?

For example if I have to execute several uri calls with the same url. In case they are next
to each other you can use a loop but otherwise you have to specify the same parameters
again and again.


Thanks,
Dennis Benzinger | hybris

Matt Martz

unread,
Nov 18, 2015, 4:11:12 PM11/18/15
to ansible...@googlegroups.com
This is technically feasible now, but it isn't specifically ansible functionality, instead it is YAML functionality.  Here is an example playbook that displays how this works:

---
- hosts: all
  gather_facts: false
  vars:
    - uri_defaults: &URI_DEFAULTS
        url: "http://httpbin.org/get"
        method: GET
  tasks:
    - uri:
        << : *URI_DEFAULTS
        status_code: 200

    - uri:
        << : *URI_DEFAULTS
        status_code: 201
      ignore_errors: true

    - uri:
        << : *URI_DEFAULTS
        status_code: 201


This uses YAML aliases, anchors, and merge functionality.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, 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/2988e835-8764-49e7-8779-dc96fee401e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages