Correct way to touch a file

Hi there!

I have added some extra commands to the build after hook in trellis:

- name: Create Wordfence WAF file
   command: touch wordfence-waf.php
   args:
     chdir: "{{ deploy_helper.new_release_path }}/web/wp/"

- name: Set owner of Wordfence WAF file to web
   command: chown web wordfence-waf.php
   args:
     chdir: "{{ deploy_helper.new_release_path }}/web/wp/"

Then I get the below:

[WARNING]: Consider using file module with state=touch rather than running touch

I know I should be doing something like this:

path={{ deploy_helper.new_release_path }}/web/wp/wordfence-waf.php
    state=touch
    owner=web
    mode=0755

But I can’t work out where this line fits in the format that I have above. Does it all just go on one line?

- name: Create Wordfence WAF file
  command: path={{ deploy_helper.new_release_path }}/web/wp/wordfence-waf.php state=touch owner=web mode=0755

See the file module docs: http://docs.ansible.com/ansible/latest/file_module.html

1 Like