043 Filters to_ucl and from_ucl

Use case

Test filters vbotka.freebsd.to_ucl and vbotka.freebsd.from_ucl

Tree

shell> tree .
.
├── ansible.cfg
├── pb-test-from-ucl.yml
└── pb-test-to-ucl.yml

Synopsis

Requirements

Notes

The filters to_ucl and from_ucl require package ucl.

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

Playbook pb-test-to-ucl.yml

- name: Test to_ucl filter.
  hosts: localhost
  connection: local

  vars:

    pkg_repo_config:
      FreeBSD:
        url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly"
        mirror_type: "srv"
        signature_type: "fingerprints"
        fingerprints: "/usr/share/keys/pkg"
        enabled: true
        priority: 100

  tasks:

    - debug:
        msg: |
          {{ pkg_repo_config | vbotka.freebsd.to_ucl }}

Playbook output - Test to_ucl filter

(env) > ansible-playbook -i localhost, pb-test-to-ucl.yml
PLAY [Test to_ucl filter.] *****************************************************

TASK [debug] *******************************************************************
ok: [localhost] => 
    msg: |-
        FreeBSD {
            url = "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly";
            mirror_type = "srv";
            signature_type = "fingerprints";
            fingerprints = "/usr/share/keys/pkg";
            enabled = true;
            priority = 100;
        }

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

Playbook pb-test-from-ucl.yml

- name: Test from_ucl filter.
  hosts: localhost
  connection: local

  vars:

    pkg_repo_config:
      FreeBSD:
        url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly"
        mirror_type: "srv"
        signature_type: "fingerprints"
        fingerprints: "/usr/share/keys/pkg"
        enabled: true
        priority: 100
    pkg_repo_ucl: |
      {{ pkg_repo_config | vbotka.freebsd.to_ucl }}

  tasks:

    - debug:
        msg: |
          {{ pkg_repo_ucl | vbotka.freebsd.from_ucl }}

Playbook output - Test from_ucl filter

(env) > ansible-playbook -i localhost, pb-test-from-ucl.yml
PLAY [Test from_ucl filter.] ***************************************************

TASK [debug] *******************************************************************
ok: [localhost] => 
    msg:
        FreeBSD:
            enabled: true
            fingerprints: /usr/share/keys/pkg
            mirror_type: srv
            priority: 100
            signature_type: fingerprints
            url: pkg+http://pkg.FreeBSD.org/${ABI}/quarterly

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