Home > Net >  Ansible refer to another directory
Ansible refer to another directory

Time:10-27

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?

CodePudding user response:

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.

  • Related