0

I would like to store the variable value to a file in new lines format.

- set_fact:
    linked_dirs:   "{{ linked_dirs.stdout_lines | select('search',nfs_server) | list }}"

- debug:  var=linked_dirs

- shell:  echo -e "{{ linked_dirs }}\n" >> /tmp/test
  delegate_to:  localhost

cat /tmp/test

[u'/net/rchserver01/data/share2 linked with /var/tmp/test2', u'/net/rchserver01/data/share2 linked with /var/tmp/share2', u'/net/rchserver01/data/share1 linked with /var/share1']

Required Result: cat /tmp/test

/net/rchserver01/data/share2 linked with /var/tmp/test2
/net/rchserver01/data/share2 linked with /var/tmp/share2
/net/rchserver01/data/share1 linked with /var/share1
0

You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.

0

First, if you have a list, you have to join() the items together.

Second, to write a file, use the copy module.

Replace the last task with something like this:

- name: Write linked_dirs file
  copy:
    content: '{{ linked_dirs("\n") }}'
    dest: /tmp/test
  delegate_to: localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.