017 community.general.iocage
Extending example 016 Multiple inventory constructed.
Use case
Use the inventory plugin community.general.iocage instead of the inventory plugin vbotka.freebsd.iocage.
Tree
shell> tree .
.
├── ansible.cfg
├── hosts
│ ├── 02_iocage.yml
│ ├── 04_iocage.yml
│ └── 99_constructed.yml
├── pb-iocage-obsolete.yml
└── pb-test.yml
Synopsis
The inventory plugin community.general.iocage should provide the same functionality.
Warning
The inventory plugin community.general.iocage may differ from
vbotka.freebsd.iocage. If you want be sure community.general.iocage
provides the same functionality, compare the hash from
setup/vars/chcksum.yml with the community.general.iocage hash. Run the
included playbook pb-iocage-obsolete.yml
shell> ansible-playbook pb-iocage-obsolete.yml
If the versions are different you’ll see a warning similar to this one
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
* WARNING *
* *
* The inventory plugins are different: *
* *
* vbotka.freebsd.iocage db8039e6 0.4.7 *
* community.general.iocage 3057fb18 10.2.0 *
* *
* Run the below commands and see the functionality provided *
* *
* shell> ansible-doc -t inventory vbotka.freebsd.iocage *
* shell> ansible-doc -t inventory community.general.iocage *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
The play shows nothing if the hashes match
shell> ANSIBLE_DISPLAY_OK_HOSTS=false \
ANSIBLE_DISPLAY_SKIPPED_HOSTS=false \
ansible-playbook pb-iocage-obsolete.yml
PLAY [Test inventory plugin version.] ****************************************
PLAY RECAP *******************************************************************
localhost: ok=3 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
Notes
Available in community.general >= 10.2.0
See
shell> ansible-doc -t inventory community.general.iocage
ansible.cfg
[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false
host_key_checking = false
[connection]
pipelining = true
Inventory hosts
hosts/02_iocage.yml
plugin: community.general.iocage
host: 10.1.0.73
user: admin
sudo: true
sudo_preserve_env: true
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
compose:
ansible_host: iocage_ip4
groups:
test_02: inventory_hostname.startswith('test')
hosts/04_iocage.yml
plugin: community.general.iocage
host: 10.1.0.29
user: admin
sudo: true
compose:
ansible_host: iocage_ip4
groups:
test_04: inventory_hostname.startswith('test')
hosts/99_constructed.yml
plugin: ansible.builtin.constructed
groups:
test: inventory_hostname.startswith('test')
Hint
List all inventory:
(env) > ansible-inventory -i hosts --list --yaml
Playbook pb-test.yml
- hosts: test
tasks:
- debug:
var: iocage_ip4
- debug:
msg: |
{% for group in groups %}
{{ group }}: {{ groups[group] }}
{% endfor %}
run_once: true
Playbook output - Display groups
(env) > ansible-playbook pb-test.yml -i hosts
PLAY [test] ********************************************************************
TASK [debug] *******************************************************************
ok: [test_111] =>
iocage_ip4: 10.1.0.111
ok: [test_112] =>
iocage_ip4: 10.1.0.112
ok: [test_113] =>
iocage_ip4: 10.1.0.113
ok: [test_131] =>
iocage_ip4: 10.1.0.131
ok: [test_132] =>
iocage_ip4: 10.1.0.132
ok: [test_133] =>
iocage_ip4: 10.1.0.133
TASK [debug] *******************************************************************
ok: [test_111] =>
msg: |-
all: ['ansible_client', 'test_111', 'test_112', 'test_113', 'test_131', 'test_132', 'test_133']
ungrouped: ['ansible_client']
test_02: ['test_111', 'test_112', 'test_113']
test_04: ['test_131', 'test_132', 'test_133']
test: ['test_111', 'test_112', 'test_113', 'test_131', 'test_132', 'test_133']
PLAY RECAP *********************************************************************
test_111 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_112 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_113 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_131 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_132 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_133 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0