On 9/21/20 7:49 AM, [email protected] 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
> [email protected] 
> <mailto:[email protected]>.
> 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.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/98cf9b8f-7282-1ac3-96f8-79250bc17383%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to