040 Lookup galaxy_info

Use case

Use the lookup vbotka.freebsd.galaxy_info to get the meta data from galaxy.yml.

Tree

shell> tree .
.
├── ansible.cfg
├── host
└── pb.yml

Synopsis

At the managed node iocage_04 in the playbook pb.yml use the lookup vbotka.freebsd.galaxy_info to:

  • display the complete meta data dictionary from galaxy.yml

  • display the attributes authors and version.

  • fail with unknown attribute.

Requirements

Notes

ansible.cfg

[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false

[connection]
pipelining = true

Inventory hosts

iocage_04 ansible_host=10.1.0.29

[iocage]
iocage_04

[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent

Playbook pb.yml

- name: Test lookup vbotka.freebsd.galaxy_info
  hosts: iocage

  tasks:
    
    - name: Get the complete meta data dictionary from galaxy.yml
      debug:
        msg: |
          type: {{ info | type_debug }}
          info:
            {{ info | to_nice_yaml }}
      vars:
        info: "{{ lookup('vbotka.freebsd.galaxy_info', 'all') }}"
    
    - name: Get the attributes authors and version.
      debug:
        msg: |
          type: {{ info | type_debug }}
          authors: {{ info.0 }}
          version: {{ info.1 }}
      vars:
        info: "{{ lookup('vbotka.freebsd.galaxy_info', 'authors', 'version') }}"

    - name: Error. Unknown attribute foo
      debug:
        var: info
      ignore_errors: true
      vars:
        info: "{{ lookup('vbotka.freebsd.galaxy_info', 'foo') }}"

Playbook output - Display the meta data from galaxy.yml

(env) > ansible-playbook pb.yml -i hosts
PLAY [Test lookup vbotka.freebsd.galaxy_info] **********************************

TASK [Get the complete meta data dictionary from galaxy.yml] *******************
ok: [iocage_04] => 
    msg: |-
        type: dict
        info:
          authors:
        - Vladimir Botka <vbotka@gmail.com>
        build_ignore:
        - TODO
        - ATTIC
        - dest
        - files/pk_admins.txt.san
        - playbooks/sensitive
        - roles/*/docs
        - .ansible
        - .ansible-lint
        - .ansible-lint.local
        - .deny
        - .done
        - .git
        - .github
        - .gitignore
        - .readthedocs.yaml
        - .yamllint
        - '*.orig'
        - '*.tar.gz'
        - '*~'
        - \#*
        dependencies:
            ansible.posix: '*'
            ansible.utils: '*'
            community.general: '*'
        description: FreeBSD collection.
        documentation: https://ansible-collection-freebsd.readthedocs.io/
        homepage: https://github.com/vbotka/ansible-collection-freebsd/wiki/
        issues: https://github.com/vbotka/ansible-collection-freebsd/issues/
        license:
        - BSD-2-Clause
        - GPL-3.0-or-later
        name: freebsd
        namespace: vbotka
        readme: README.md
        repository: https://github.com/vbotka/ansible-collection-freebsd/
        tags:
        - freebsd
        - iocage
        - infrastructure
        version: 0.8.2

TASK [Get the attributes authors and version.] *********************************
ok: [iocage_04] => 
    msg: |-
        type: list
        authors: ['Vladimir Botka <vbotka@gmail.com>']
        version: 0.8.2

TASK [Error. Unknown attribute foo] ********************************************
[ERROR]: Task failed: Error while resolving `var` expression: The lookup plugin 'vbotka.freebsd.galaxy_info' failed: Unknown attribute "foo"

Task failed.
Origin: /export/scratch/collections/ansible_collections/vbotka/freebsd/docs/source/examples/040/pb.yml:24:7

22         info: "{{ lookup('vbotka.freebsd.galaxy_info', 'authors', 'version') }}"
23
24     - name: Error. Unknown attribute foo
         ^ column 7

<<< caused by >>>

Error while resolving `var` expression: The lookup plugin 'vbotka.freebsd.galaxy_info' failed: Unknown attribute "foo"
Origin: /export/scratch/collections/ansible_collections/vbotka/freebsd/docs/source/examples/040/pb.yml:26:14

24     - name: Error. Unknown attribute foo
25       debug:
26         var: info
                ^ column 14

fatal: [iocage_04]: FAILED! => 
    msg: 'Task failed: Error while resolving `var` expression: The lookup plugin ''vbotka.freebsd.galaxy_info''
        failed: Unknown attribute "foo"'
...ignoring

PLAY RECAP *********************************************************************
iocage_04                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1