Skip to content

Instantly share code, notes, and snippets.

@jostmart
Forked from halberom/00_play.yml
Created May 30, 2019 13:53
Show Gist options
  • Save jostmart/47d94700351fa5f1f99d06e7bb7937f1 to your computer and use it in GitHub Desktop.
Save jostmart/47d94700351fa5f1f99d06e7bb7937f1 to your computer and use it in GitHub Desktop.
ansible - example of using selectattr to filter on attrs that are defined and true
---
- 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 }}"
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