0

I need to update some files via Ansible playbook.

Normally my playbook would connect to the site where the new files are stored and transfers them.

The question is if there is a way to have the content of the new files integrated inside the playbook to have it bundled together without needing to have a download site.

I think of HTML and images. You can reference to another file or also can have it inlined Base64 encoded.

EDIT

Just found module copy supports inline data.

- name: Creating a file with content
    copy:
      dest: "x.x"
      content: |
        line1abc  xyz
        yxz000  123
        blabla *** ...

Thats a possible way for me. Maybe there is some better - let me know please.

1
  • by default the ansible.builtin.copy module looks for files in the files/ subdir of the current directory (or relative to the role's root if in a role). Can't you just put the file there? It'll have the same result as inlining it and will look much less cluttered.
    – Shadur
    Oct 3, 2023 at 9:19

1 Answer 1

-1

While your approach with ansible.builtin.copy and content works, it will not scale for large numbers of files.

I would suggest you take a look at the docs for ansible.posix.synchronize and ansible.builtin.git

The synchronize-module is basically a wrapper around rsync.

For html-files or any other code, you should use git anyway, so you can leverage it for the file-transfer. The depth-attribute of the git-module is of interest here: you probably want a shallow clone with a depth of 1 on your webserver, not a full clone of your local repo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .