What's the easy way to auto create non existing dir in ansible

前端 未结 7 658
悲哀的现实
悲哀的现实 2020-12-23 15:37

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.         


        
相关标签:
7条回答
  • 2020-12-23 16:27

    AFAIK, the only way this could be done is by using the state=directory option. While template module supports most of copy options, which in turn supports most file options, you can not use something like state=directory with it. Moreover, it would be quite confusing (would it mean that {{project_root}}/conf/code.conf is a directory ? or would it mean that {{project_root}}/conf/ should be created first.

    So I don't think this is possible right now without adding a previous file task.

    - file: 
        path: "{{project_root}}/conf"
        state: directory
        recurse: yes
    
    0 讨论(0)
提交回复
热议问题