How to create an empty file with Ansible?

后端 未结 10 801
傲寒
傲寒 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条回答
  •  旧时难觅i
    2021-01-31 13:35

    Something like this (using the stat module first to gather data about it and then filtering using a conditional) should work:

    - stat: path=/etc/nologin
      register: p
    
    - name: create fake 'nologin' shell
      file: path=/etc/nologin state=touch owner=root group=sys mode=0555
      when: p.stat.exists is defined and not p.stat.exists
    

    You might alternatively be able to leverage the changed_when functionality.

提交回复
热议问题