I'm writing an Ansible script to automatically add users to servers. The first step is uses the URI module to make a rest call to an intranet server to pull the public key for each user, which is stored in user_keys dict
Now I want to loop over user_keys.results and for each element apply a regex to to the key (ie item.content) to find the uid of the user. The uid is in the key and can be found with the regex 'unixid=\d+'
However, I'm struggling to get this to work.
I know I can use combine to append to the item array, and that I can use regex_search to do a search on item.content. However, I can't seem to combine the two in one command. In fact even this simpler test fails:
- name: set key for user
set_fact:
item: "{{ item | combine({'key: {{item.content}} }) }}
with_items: "{{ user_keys.results }}"
Though the similar command:
- name: set key for user
set_fact:
item: "{{ item | combine({'key: 'dummy_key' }) }}
with_items: "{{ user_keys.results }}"
works fine. That suggests that Ansible doesn't like my nesting variable references (ie no recursive uses of the {{ }} sections). But given that how can I pull out the uid from the key and save it so I can use it in future commands?
I'm using ansible 2.10.9