Question:
In my Ansible playbook many times i need to create file there
1 2 3 4 5 |
- name: Copy file template: src: code.conf.j2 dest: "{{project_root}}/conf/code.conf" |
now many times conf
dir is not there. Then I have to create more task to create that dir first.
Is there any easy way to auto create dir if don’t exist with some option
Answer:
Right now, this is the only way
1 2 3 4 5 6 7 |
- name: Ensures {{project_root}}/conf dir exists file: path={{project_root}}/conf state=directory - name: Copy file template: src: code.conf.j2 dest: "{{project_root}}/conf/code.conf" |