how to add new line character in copy module to write multiple lines

Hi All,

I want to write few lines into a file using copy module by line by line but it’s not happening,

  • name: “Storing the data details”
    copy:
    content: ’ IP: xx.xx.xx.xx \n
    IPV4: xx.xx.xx.xx \n
    HOST_NAME: {{host_name}} \n
    Network: {{network}} \n’
    dest: “/root/home/network.conf”

Excepted o/p:
IP: xx.xx.xx.xx
IPV4: xx.xx.xx.xx
HOST_NAME: some_name
Network: local

Actual o/p:
IP:xx.xx.xx.xx \n IPV4: xx.xx.xx.xx \n HOST_NAME: some_name \n Network: local \n

how can i achieve this as i want in Excepted one.

Hi,

I want to write few lines into a file using copy module by line by
line but it's not happening,

- name: "Storing the data details"
  copy:
         content: ' IP: xx.xx.xx.xx \n
                         IPV4: xx.xx.xx.xx \n
                         HOST_NAME: {{host_name}} \n
                         Network: {{network}} \n'
         dest: "/root/home/network.conf"

Excepted o/p:
       IP: xx.xx.xx.xx
       IPV4: xx.xx.xx.xx
       HOST_NAME: some_name
       Network: local

Actual o/p:
        IP:xx.xx.xx.xx \n IPV4: xx.xx.xx.xx \n HOST_NAME: some_name
\n Network: local \n

how can i achieve this as i want in Excepted one.

replace the single quotes by double quotes:

- name: "Storing the data details"
   copy:
          content: " IP: xx.xx.xx.xx \n
                          IPV4: xx.xx.xx.xx \n
                          HOST_NAME: {{host_name}} \n
                          Network: {{network}} \n"
          dest: "/root/home/network.conf"

Cheers,
Felix

That worked :)…! thanks Felix