Yaml statement over multiple lines.

Hi,

How should I split this dest: statement into multiple lines ?

  • copy:
    content: “{{ config.stdout[0] }}”
    dest: “{{ backup_root }}/{{ inventory_hostname }}/dhcp_leases_{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}”

Thanks in advance,

Phil.

You can try this

  - copy:
      content: "{{ config.stdout[0] }}"
      dest: "{{ backup_root }}/\
        {{ inventory_hostname }}/\
        dhcp_leases_{{ ansible_date_time.year }}\
        {{ ansible_date_time.month }}\
        {{ ansible_date_time.day }}\
        {{ ansible_date_time.hour }}\
        {{ ansible_date_time.minute }}\
        {{ ansible_date_time.second }}"

There are multiple ways to do it, but I’d go for something like this:

dest: “{{ [ backup_root, inventory_hostname, ‘dhcp_leases_’ ~
(‘%Y%m%d%H%M%S’ | strftime) ] | join(‘/’) }}”

(If using the time from the facts is important, you can do “strftime(ansible_date_time.epoch)” instead of the plain invocation.)