In ansible if there is list of host names with fully qualified domain name:
"groups[group_names[0]]": [
"node1.in.labs.corp.netin",
"node2.in.labs.corp.netin"
]
How to obtain only node names from these strings? Say , answer list should have only these entries:
[node1 , node2]
Tried using map and split operation, But it does not seem to work.It fails saying split operation is not defined for map.
msg={{ groups[group_names[0]] | map('split','@') | flatten }}
Is there any other way ? Thank you in advance.
I tried using regex_replace option this way:
Here groups[group_names[0]] is list of node names
"groups[group_names[0]]": [
"node1.in.labs.corp.netin",
"node2.in.labs.corp.netin"
]
- set_fact:
groups[group_names[0]]={{ groups[group_names[0]] |
map('regex_replace', _regex, _replace)|list }}
vars:
_regex: '^(.*?)\.(.*)$'
_replace: '-n \1'
Hitting the following error line:
{"changed": false, "msg": "The variable name 'groups[group_names[0]]' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores."}
Can i assign back to same list ? after replacing the regex ? Also -n option is using so that my expected output should be
-n node1 -n node2