Given a list of users:
# Python Syntax
users = [{'name': 'alice', 'sudo': True}, {'name': 'bob'}, {'name': 'charlie'}]
# YAML Syntax
users:
- name: alice
sudo: yes
- name: bob
- name: charlie
How would I do the following in an ansible playbook:
# Python Syntax
[ dict(user, home="/home/{}/".format(user['name'])) for user in users if not 'sudo' in user]
# more verbose
for user in users:
if not 'sudo' in user:
user['home'] = '/home/' + user['name'] + '/'
resulting in:
# Python Syntax
[{'name': 'bob', 'home': '/home/bob/'}, {'name': 'charlie', 'home': '/home/charlie/'}]
# YAML Syntax
users:
- name: bob
home: /home/bob/
- name: charlie
home: /home/charlie/
Is this even possible/intended use of playbook language?