041 Filter project
Use case
Use the filter vbotka.freebsd.project to restructure a project dictionary.
Tree
shell> tree .
.
├── ansible.cfg
└── pb.yml
Synopsis
Restructure a dictionary of jails and their hosts defined with vmm and
class attributes.
Groups full service specifications under their respective host (
vmm).Inverts the
classattribute into a reverse-lookup dictionary mapping class names to lists ofjails.
Requirements
Notes
See Project.
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.yml
---
- name: Test filter project.
hosts: localhost
connection: local
vars:
project:
logserv-1:
class: [logserv]
vmm: iocage_01
http-1:
class: [http, logclient]
vmm: iocage_02
db-1:
class: [db, logclient]
vmm: iocage_02
http-2:
class: [http, logclient]
vmm: iocage_04
db-2:
class: [db, logclient]
vmm: iocage_04
vmm: "{{ (project | vbotka.freebsd.project).vmm }}"
class: "{{ (project | vbotka.freebsd.project).class }}"
tasks:
- debug:
msg: |
vmm:
{{ vmm | to_yaml(indent=2) | indent(2) }}
- debug:
msg: |
class:
{{ class | to_yaml(indent=2) | indent(2) }}
Playbook output - Test filter project
(env) > ansible-playbook -i localhost, pb.yml
PLAY [Test filter project.] ****************************************************
TASK [debug] *******************************************************************
ok: [localhost] =>
msg: |-
vmm:
iocage_01:
logserv-1:
class: [logserv]
vmm: iocage_01
iocage_02:
db-1:
class: [db, logclient]
vmm: iocage_02
http-1:
class: [http, logclient]
vmm: iocage_02
iocage_04:
db-2:
class: [db, logclient]
vmm: iocage_04
http-2:
class: [http, logclient]
vmm: iocage_04
TASK [debug] *******************************************************************
ok: [localhost] =>
msg: |-
class:
db: [db-1, db-2]
http: [http-1, http-2]
logclient: [http-1, db-1, http-2, db-2]
logserv: [logserv-1]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0