0

I have a remote file (two actually) that I wish to concat to another remote file. I want to use the command module in Ansible rather than the shell module. Therefore I can't use >> (or | or && etc).

Question is twofold: is there a module (or combination) that will do this for me?

And, if not, is there a bash command which will do this for me?

I know from this question that sed -i "$ a some text" somefile.txt will append a line of text.

A hypothetical command to illustrate:

append -in /my/remote/file -in /my/remote/file2 -out /my/remote/dst
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
SeamusJ
  • 401
  • 5
  • 10

2 Answers2

3

With GNU sed, you could use in-place editing and the r command:

sed -i '$r file2' file

which on the last line of file will append (r for "read") the contents of file2.

As for an Ansible module, I don't know Ansible well at all, but blockinfile might work?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
1

Not sure if your requirement has all file to be merged in one folder. If so, you can use below code

- name: Assemble from fragments from a directory
  assemble:
   src: /my/remote/
   dest: /my/remote/dst
Initial:
# ls
file1  file2
# cat file1
this is file1
# cat file2
this is file2

After running playbook:
# cat dst
this is file1
this is file2
Smily
  • 2,308
  • 2
  • 17
  • 41