BlockinFile module help

19 views
Skip to first unread message

Akshay Kumar

unread,
Mar 4, 2021, 5:11:13 AM3/4/21
to Ansible Project
Hi Guys ,

I am using the below block for writing a variable values into a file

  - name: Add output of task for getting content to the local
    local_action:
      module: blockinfile
      path: "{{ File }}"
      marker: " "
      state: present
      block: |
           {{ item }}:
           {{ hostvars[item]['CronOutput'].stdout | default(['No Cron Entries'])  }}
      insertafter: EOF
    run_once: true
    with_items:
      - "{{ play_hosts }}"

In this for a host when there is not value in "CronOutput" variable , i want Default string to be printed into file for that host but it is not working , anyonw have an idea about the same?

I tried this also :
{{ hostvars[item]['CronOutput'].stdout | default('No Cron Entries')  }}
{{ hostvars[item]['CronOutput'].stdout | default("No Cron Entries")  }}

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages