Formatting with set_fact

31 views
Skip to first unread message

Veera

unread,
Jun 13, 2023, 6:52:44 AM6/13/23
to Ansible Project
Hi, 

While using set_facts , I am combining a hostname and dns name .
myhost = linuxhost1
mydns = example.com.


while  combining them  with set_fact 

ansible.builtin.set_fact:
   my_fqdn:  "{{myhost}}.{{mydns}}"

 
This gives the desired output of "linuxhost1.example.com."
The last dot can be cut with [:-1] with debug , however I want to set this in set_fact itself as I am trying to write the FQDN without a dot to the inventory file. 




Will McDonald

unread,
Jun 13, 2023, 7:20:14 AM6/13/23
to ansible...@googlegroups.com
This should do the trick:

"{{myhost}}.{{mydns | trim('.')}}"

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ebdb13fe-035d-473a-9904-277a11d8e285n%40googlegroups.com.

Abhijeet Janwalkar

unread,
Jun 13, 2023, 7:22:43 AM6/13/23
to ansible...@googlegroups.com
Hi all,
Where can I see the available options like
 | trim('.') which i can use in playbook.

Warm Regards,
Abhi

Veeramani Sonai

unread,
Jun 13, 2023, 7:34:02 AM6/13/23
to ansible...@googlegroups.com
Thanks .. It worked 

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/j2kYkv6vPc4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKtKohQ%2BOx%3DikVNL8sxXBXqLmRO0BW8ZTj6Wev5gy_-0dcyTaQ%40mail.gmail.com.

Dick Visser

unread,
Jun 13, 2023, 7:42:11 AM6/13/23
to ansible...@googlegroups.com
On Tue, 13 Jun 2023 at 13:22, Abhijeet Janwalkar <abhijeet....@gmail.com> wrote:
Hi all,
Where can I see the available options like
 | trim('.') which i can use in playbook.

Reply all
Reply to author
Forward
0 new messages