splitting the output of {{ ansible_play_name }}

12 views
Skip to first unread message

dulh...@mailbox.org

unread,
Jul 6, 2023, 3:11:03 AM7/6/23
to ansible...@googlegroups.com
I have a tasks that writes information gathered from remotes to a csv file on localhost
 
 
====================================================================
- name: write result to output.csv
  delegate_to: localhost
  lineinfile:
    dest: "./temp/{{ ansible_play_name }}.csv"
    line: >
    {{ ansible_fqdn }};{{ ansible_eth0.ipv4.address }};{{ ansible_distribution }} {{ ansible_distribution_version }};{{ ansible_play_name }};{{ pg_encoding.stdout }}
    insertafter: EOF
 
====================================================================
 
 
now ... the ansible_play_name is i.e. POSTGRES_get_utf8.
How can I only get POSTGRES to be written out to the csv. I guess 'split' being part of the solution, but how exactly?

Vladimir Botka

unread,
Jul 6, 2023, 3:43:25 AM7/6/23
to dulhaver via Ansible Project
On Thu, 6 Jul 2023 09:10:48 +0200 (CEST)
dulhaver via Ansible Project <ansible...@googlegroups.com> wrote:

> ansible_play_name is i.e. POSTGRES_get_utf8.
> How can I only get POSTGRES

Try this

{{ ansible_play_name|split('_')|first }}

--
Vladimir Botka

dulh...@mailbox.org

unread,
Jul 6, 2023, 4:15:03 AM7/6/23
to ansible...@googlegroups.com
thanks. I guess that is pretty much the same thing as ...

{{ ansible_play_name.split('_')[0] }}

... (which I figured out in the meantime).
Reply all
Reply to author
Forward
0 new messages