0

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?

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.