040 Lookup galaxy_info

Use case

Use the lookup vbotka.freebsd.galaxy_info plugin to get the metadata from galaxy.yml.

Tree

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

Synopsis

On a managed node, in the playbook pb.yml, use the lookup vbotka.freebsd.galaxy_info plugin to:

  • Display the complete metadata dictionary from galaxy.yml

  • Display the attributes authors and version

ansible.cfg

[defaults]
callback_result_format = yaml
deprecation_warnings = False
display_skipped_hosts = False
gathering = explicit
interpreter_python = auto_silent
log_path = /var/log/ansible.log

[connection]
pipelining = true

hosts

iocage_06

[iocage]
iocage_06

[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
      vars:
        info: "{{ lookup('vbotka.freebsd.galaxy_info', 'all') }}"
      debug:
        msg: |
          type: {{ info | type_debug }}
          info:
            {{ info | to_nice_yaml }}
    
    - name: Get the attributes authors and version.
      vars:
        info: "{{ lookup('vbotka.freebsd.galaxy_info', 'authors', 'version') }}"
      debug:
        msg: |
          type: {{ info | type_debug }}
          authors: {{ info.0 }}
          version: {{ info.1 }}

#   - name: Error. Unknown attribute foo
#     block:
#        - set_fact:
#           foo: "{{ query('vbotka.freebsd.galaxy_info', 'foo') }}"
#        - debug:
#           var: foo
#      rescue:
#        - debug:
#           var: ansible_failed_result

Playbook output - Display the metadata from galaxy.yml

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

TASK [Get the complete meta data dictionary from galaxy.yml] *******************
ok: [iocage_06] => 
    msg: |-
        type: dict
        info:
          authors:
        - Vladimir Botka <vbotka@gmail.com>
        build_ignore:
        - TODO
        - ATTIC
        - dest
        - jailexec.py
        - files/pk_admins.txt.san
        - playbooks/sensitive
        - roles/*/docs
        - .ansible
        - .ansible-lint
        - .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:
        - GPL-3.0-or-later
        - BSD-2-Clause
        name: freebsd
        namespace: vbotka
        readme: README.md
        repository: https://github.com/vbotka/ansible-collection-freebsd/
        tags:
        - freebsd
        - iocage
        - infrastructure
        version: 1.0.2

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

PLAY RECAP *********************************************************************
iocage_06                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0