On 24.08.2019 07:11, Nicholas Britton wrote:
I got it to work with this:
- name : print all hostgroups
debug:
msg:
"{{item.hostGroup.hostGroupName}},{{item.hostGroup.hostGroupId}}"
loop: "{{sessions.json.data}}"
when: item.hostGroup.hostGroupName |
regex_search('.*am1.*')(.*\.9$)
I cant get the regex to work right. I am looking to match am1
anywhere
in the string, but end with specific numbers such as 1-8 or 9-16. Any
help there would be appreciated.
You can eliminate when by using Jinja filter, i would recommend reading
about all of them[1]
- name : print all hostgroups
debug:
msg:
"{{item.hostGroup.hostGroupName}},{{item.hostGroup.hostGroupId}}"
loop: "{{ sessions.json.data | selectattr('hostGroup.hostGroupName',
'search', 'am1.*9$') | list }}"
selectattr is a Jinja filter and search is a Ansible regex contains
filter.
My next step will be to figure out how to do a loop and do something
with
that data. such as execute a uri block that will use the item.####
as
inputs to the body of the uri call. I have not had much luck locating
what i think would do that, if someone has an example that would be
great.
Wouldn't that just be to use the uri module with the loop above and just
{{ item.xxxx }} where every you need.
[1]
https://jinja.palletsprojects.com/en/2.10.x/templates/#list-of-builtin-filters
--
Kai Stian Olstad
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/8b1ca238d9d91fdc00d8fe198b3ef533%40olstad.com.