Reading partial string

20 views
Skip to first unread message

dudu.c...@gmail.com

unread,
Sep 21, 2020, 1:49:48 AM9/21/20
to Ansible Project

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

Stefan Hornburg (Racke)

unread,
Sep 21, 2020, 2:43:57 AM9/21/20
to ansible...@googlegroups.com
On 9/21/20 7:49 AM, dudu.c...@gmail.com wrote:
> 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
Racke

>  
>
>  *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
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/272a5ee9-5200-4390-98d9-1d51f469b051n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/272a5ee9-5200-4390-98d9-1d51f469b051n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages