Ansible include task and loop register different result

Viewed 29

I'm trying to use a module as an included task so I can loop several items and register the credentials in a variable.

Files:

main.yml:

---
- hosts: localhost
  gather_facts: False
  tasks:

  - include: tasks/myvault/get-vault.yml
    with_items:
      - demo
    register: output

  - debug:
      msg: "{{output}}"

get-vault.yml:

- name: Retrieve secret from Vault
  community.hashi_vault.vault_kv2_get:
    url: https://myvaul
    path: "{{  item  }}"
    auth_method: token
    token: '{{ mytoken }}'
    namespace: MyNamespace
    validate_certs: no

output:

ok: [localhost] => {
    "msg": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "ansible_loop_var": "item",
                "include": "tasks/myvault/get-vault.yml",
                "include_args": {},
                "item": "demo"
            }
        ],
        "skipped": false
    }
}

The output doesn't display the "real" result of the task. If I remove: register: output and put it in get-vault.yml, here is the result:

ok: [localhost] => {
    "msg": {
        "changed": false,
        "data": {
            "data": {
                "password": "Password",
                "username": "Username"
            }, ...

How can I get this result returned when I register the output from my included task?

0 Answers
Related