# Reading partial string

**URL:** <https://forum.ansible.com/t/reading-partial-string/33855>\
**Category:** Ansible Project\
**Created:** [September 21, 2020, 5:49am UTC](https://forum.ansible.com/t/reading-partial-string/33855 "2020-09-21T05:49:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudu.c](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dudu.c](https://forum.ansible.com/u/dudu.c)\
**Post date:** [September 21, 2020, 5:49am UTC](https://forum.ansible.com/t/reading-partial-string/33855/1 "2020-09-21T05:49:47Z")

</div>

Hi,

I have a simple playbook that takes an IP address from the input file and update this IP including hostname under /etc/hosts.

The problem is that in the input file the IP is written with subnet – 1.1.1.1/24

While I need only the IP 1.1.1.1

**Playbook :**

- hosts: localhost

become: true

any\_errors\_fatal: true

gather\_facts: False

vars\_files:

- /opt/ input-file.yml

tasks:

- name: Update server etc/host with response ip

lineinfile:

path: /etc/hosts

line: “{{ lb\_ext\_ip }} hdfs”

state: present

backup: yes

**Result in /etc/hosts**

1.1.1.1/24 hdfs

**Required results:**

1.1.1.1 hdfs

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [September 21, 2020, 6:43am UTC](https://forum.ansible.com/t/reading-partial-string/33855/2 "2020-09-21T06:43:24Z")

</div>

> Hi,
> 
> I have a simple playbook that takes an IP address from the input file and update this IP including hostname under  
> /etc/hosts.
> 
> The problem is that in the input file the IP is written with subnet – 1.1.1.1/24
> 
> While I need only the IP 1.1.1.1

Use the ipaddr filter:

{{ lb\_ext\_ip | ipaddr('address') }}

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
