Hi,

I am writing a role that contains a dozen of tasks that invoke REST APIs. 
All tasks have a set of common and identical configurations:

- name: Task 1
  uri:
    validate_certs: False
    method: POST
    user: "{{ user }}"
    password: "{{ pass }}"
    force_basic_auth: yes
    body_format: json


I am looking for a way to avoid repeating these parameters for all the 
tasks. One way is to use anchors:

api_defaults: &API_DEFAULTS
  validate_certs: False
  method: POST
  user: "{{ user }}"
  password: "{{ pass }}"
  force_basic_auth: yes
  body_format: json


Then I can reuse this similar to:

- name: Task 1
  uri:
    << *API_DEFAULTS


However, I still have to repeat the "<< *API_DEFAULTS" everywhere. Are 
there any other options available, other than developing new modules?

For example to "define" modules based on existing modules, in a way similar 
to:

- name: Define api
  extend_module:
    parent_module: uri
    module_name: api
    defaults:
      validate_certs: False
      method: POST
      user: "{{ user }}"
      password: "{{ pass }}"
      force_basic_auth: yes
      body_format: json


And then use it like:

- name: Task 1
  api:
    body:
      a: 1
      b: c


Thanks in advance.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4b750222-7c27-40b8-830f-010e8858fc1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to