What's the easy way to auto create non existin

2020-05-14 13:31发布

In my Ansible playbook many times i need to create file there

 - 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

标签: ansible
7条回答
乱世女痞
2楼-- · 2020-05-14 14:04

Right now, this is the only way

- 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"
查看更多
登录 后发表回答