Created
May 12, 2017 09:33
-
-
Save halberom/3659c98073efcabd91ed1dec3ad63fa3 to your computer and use it in GitHub Desktop.
ansible - example of using selectattr to filter on attrs that are defined and true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: False | |
vars: | |
apache2_vhosts: | |
- name: "stage.example.org" | |
docroot: "/var/www/stage1" | |
- name: "stage2.example.org" | |
docroot: "/var/www/stage2" | |
letsencrypt: no | |
- name: "www.example.org" | |
docroot: "/var/www/www" | |
letsencrypt: yes | |
tasks: | |
- debug: | |
msg: "{{ apache2_vhosts | selectattr('letsencrypt', 'defined') | selectattr('letsencrypt', 'equalto', True) | list }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLAY [localhost] ********************************************************************************************************************** | |
TASK [debug] ************************************************************************************************************************** | |
ok: [localhost] => { | |
"changed": false, | |
"msg": [ | |
{ | |
"docroot": "/var/www/www", | |
"letsencrypt": true, | |
"name": "www.example.org" | |
} | |
] | |
} | |
PLAY RECAP **************************************************************************************************************************** | |
localhost : ok=1 changed=0 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fatal: [localhost]: FAILED! =>
msg: Unexpected failure during module execution.
@halberom