Yaml statement over multiple lines.

16 views
Skip to first unread message

mail.ph...@gmail.com

unread,
Feb 13, 2018, 7:25:24 AM2/13/18
to Ansible Project
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.

Kai Stian Olstad

unread,
Feb 13, 2018, 9:33:11 AM2/13/18
to ansible...@googlegroups.com
On Tuesday, 13 February 2018 13.25.24 CET mail.ph...@gmail.com wrote:
> 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 }}"*

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 }}"


--
Kai Stian Olstad

flowerysong

unread,
Feb 13, 2018, 9:29:14 PM2/13/18
to Ansible Project
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.)
Reply all
Reply to author
Forward
0 new messages