<p>There is <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html" rel="nofollow noreferrer">module_defaults</a> playbook-level option:</p>

<pre><code>- hosts: localhost
  module_defaults:
    file:
      owner: root
      group: root
      mode: 0755
  tasks:
    - file:
        state: touch
        path: /tmp/file1
    - file:
        state: touch
        path: /tmp/file2
</code></pre>

CC BY-SA 4.0
2019-02-20T06:30:48.540Z
2019-02-20T07:18:22.773Z
2019-02-20T07:18:22.773Z
Konstantin Suvorov
<p>Using Ansible with the <strong>aci_rest</strong> module, requires the authentication parameters (<em>hostname, username, password, method, validate_certs</em>) to be defined in every task e.g.</p>

<pre><code>aci_rest:
  hostname: "{{ inventory_hostname }}"
  username: "{{ apic_username }}"
  password: "{{ apic_password }}"
  method: post
  validate_certs: no
  path: /api/node/mo/uni/controller/nodeidentpol.json
  method: post
  ...etc
</code></pre>

<p>The YML Anchors, Aliases syntax works perfectly fine within one file. </p>

<pre><code>- aci_rest:
    &lt;&lt;: *aci_login
    path: /api/node/mo/uni/controller/nodeidentpol.json
    method: post
    ...etc
</code></pre>

<p>However not when variables and tasks are in different files using any of these functions:</p>

<pre><code>vars_files:
include_tasks:
include_vars:
</code></pre>

<p>The full playbook has 70+ tasks with the authentication info repeated every time. I have not been able to find a way to not use repeat code. Is there a way to do this similar to yml alias?</p>

<ansible>
Looking for Ansible equivalent method to yml Anchors, Aliases, when using include file
wiggwire
# Looking for Ansible equivalent method to yml Anchors, Aliases, when using include file

(Asked by: username_0 on 2019-02-20)

Using Ansible with the aci_rest module, requires the authentication parameters (hostname, username, password, method, validate_certs) to be defined in every task e.g.
aci_rest:
  hostname: "{{ inventory_hostname }}"
  username: "{{ apic_username }}"
  password: "{{ apic_password }}"
  method: post
  validate_certs: no
  path: /api/node/mo/uni/controller/nodeidentpol.json
  method: post
  ...etc

The YML Anchors, Aliases syntax works perfectly fine within one file. 
- aci_rest:
    <<: *aci_login
    path: /api/node/mo/uni/controller/nodeidentpol.json
    method: post
    ...etc

However not when variables and tasks are in different files using any of these functions:
vars_files:
include_tasks:
include_vars:

The full playbook has 70+ tasks with the authentication info repeated every time. I have not been able to find a way to not use repeat code. Is there a way to do this similar to yml alias?

**Tags:** ansible


---

## 1 answers

### Answer by username_1 on 2019-02-20. Score: 1 | Accepted answer

There is module_defaults playbook-level option:
- hosts: localhost
  module_defaults:
    file:
      owner: root
      group: root
      mode: 0755
  tasks:
    - file:
        state: touch
        path: /tmp/file1
    - file:
        state: touch
        path: /tmp/file2


---

