title: Ansible: How to use split strings based on a delimiter(.) using maps for items present in list
body: <p>In ansible if there is list of host names with fully qualified domain name:</p>
  <pre><code> &quot;groups[group_names[0]]&quot;: [
          &quot;node1.in.labs.corp.netin&quot;,
          &quot;node2.in.labs.corp.netin&quot;
      ]
  </code></pre>
  <p>How to obtain only node names from these strings?  Say , answer list should have only these entries:</p>
  <p>[node1 , node2]</p>
  <p>Tried using map and split operation, But it does not seem to work.It fails saying split operation is not defined for map.</p>
  <pre><code>msg={{ groups[group_names[0]] | map('split','@') | flatten }}
  </code></pre>
  <p>Is there any other way ? Thank you in advance.</p>
  <hr />
  <p>I tried using regex_replace option this way:</p>
  <p>Here groups[group_names[0]] is list of node names</p>
  <pre><code> &quot;groups[group_names[0]]&quot;: [
          &quot;node1.in.labs.corp.netin&quot;,
          &quot;node2.in.labs.corp.netin&quot;
      ]
  </code></pre>
  <pre><code>- set_fact:
        groups[group_names[0]]={{ groups[group_names[0]] |
                     map('regex_replace', _regex, _replace)|list }}
    vars:
      _regex: '^(.*?)\.(.*)$'
      _replace: '-n \1'
  </code></pre>
  <p>Hitting the following error line:</p>
  <pre><code>{&quot;changed&quot;: false, &quot;msg&quot;: &quot;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.&quot;}
  </code></pre>
  <p>Can i assign back to same list ? after replacing the regex ?
  Also -n option is using so that my expected output should be</p>
  <pre><code>-n node1 -n node2
  
  </code></pre>