Skip to content

Instantly share code, notes, and snippets.

@VireshDoshi
Created February 18, 2018 21:08
Show Gist options
  • Save VireshDoshi/213e90cc172bbf8489bf0cf2cadc0e3a to your computer and use it in GitHub Desktop.
Save VireshDoshi/213e90cc172bbf8489bf0cf2cadc0e3a to your computer and use it in GitHub Desktop.
[vdo023@localhost selectattr]$ ansible-playbook -i "localhost," ./selectattr-playbook.yml
PLAY [localhost] **********************************************************************************************************************************
TASK [extract the emails for users without a password] ********************************************************************************************
ok: [localhost]
TASK [debug message] ******************************************************************************************************************************
ok: [localhost] => (item=johnsmith@gmail.com) => {
"changed": false,
"item": "johnsmith@gmail.com",
"msg": "email this user johnsmith@gmail.com and ask them to set a password"
}
ok: [localhost] => (item=janedoe@hotmail.com) => {
"changed": false,
"item": "janedoe@hotmail.com",
"msg": "email this user janedoe@hotmail.com and ask them to set a password"
}
PLAY RECAP ****************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
---
- hosts: localhost
gather_facts: False
connection: local
vars:
users:
- name: john
email: johnsmith@gmail.com
- name: jane
email: janedoe@hotmail.com
- name: fred
email: fredbloggs@outlook.com
password: 123!abc
tasks:
- name: extract the emails for users without a password
set_fact:
emails: "{{ users | selectattr('password', 'undefined') | map(attribute='email') | list }}"
- name: debug message
debug:
msg: "email this user {{ item }} and ask them to set a password"
with_items: "{{ emails }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment