Saturday, October 29, 2022

[SOLVED] Ansible refer to another directory

Issue

I have the following structure:

  • files
  • ansible:
    • playbooks
    • templates
    • files

And my playbook.yml is inside playbooks folder:

  - name: "Write variable to file"
  vars:
    db_password: "{{ db_pass }}"
  template:
    src: templates/test.yml.j2
    dest: files/test.yml

But I cannot make it work, the error is : "msg": "Could not find or access 'templates/test.yml.j2' "msg": "Could not find or access 'templates/test.yml.j2'

How can I make my src and dest refer to files that are not in the same folder as playbook?


Solution

The files and templates folder isn't in the playbook directory, so you need to reference it like this:

  template:
    src: ../templates/test.yml.j2
    dest: ../files/test.yml

If I am mistaken, please send a better description of your folder structure.



Answered By - Nuno Oliveira
Answer Checked By - Mildred Charles (WPSolving Admin)