title: Ansible - Replace the host part of an ipv4 address
body: <pre><code>- hosts: localhost
    gather_facts: False
  
    vars_prompt:
      - name: ServerIP
        prompt: Enter the ServerIP to replace
        private: False
        default: "11.11.4.10"
  
    vars:
      Y: '126'
  
    pre_tasks:
      - name: Set some facts
        set_fact:
          ServerIP1: "{{ServerIP}}"
  
      - name: Save ServerIP in a register
        shell: echo {{ServerIP1}}
        register: resultip
  </code></pre>
  
  <p>Note: I know I can split the host portion of the Ip using the following code:</p>
  
  <pre><code>- name: show the last octet of the ServerIP
    debug: msg={{resultip.stdout.split('.')[3]}}
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>- name: Replace the last octet of the ServerIP with a variable var
    # How can I do this ?
  </code></pre>
  
  <p>I want to store/display:       </p>
  
  <p><strong>x.x.x.{{ Y }}</strong></p>