How to create an empty file with Ansible?

后端 未结 10 754
傲寒
傲寒 2021-01-31 12:53

What is the easiest way to create an empty file using Ansible? I know I can save an empty file into the files directory and then copy it to the remote host, but I f

10条回答
  •  生来不讨喜
    2021-01-31 13:45

    Turns out I don't have enough reputation to put this as a comment, which would be a more appropriate place for this:

    Re. AllBlackt's answer, if you prefer Ansible's multiline format you need to adjust the quoting for state (I spent a few minutes working this out, so hopefully this speeds someone else up),

    - stat:
        path: "/etc/nologin"
      register: p
    
    - name: create fake 'nologin' shell
      file:
        path: "/etc/nologin"
        owner: root
        group: sys
        mode: 0555
        state: '{{ "file" if  p.stat.exists else "touch" }}'
    

提交回复
热议问题