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.