Create File
1---
2- hosts: localhost
3 become: true
4
5 tasks:
6 - name: Create file
7 file:
8 path: /tmp/yallo
9 state: touch
Ref http://docs.ansible.com/ansible/latest/file_module.html
An alternative is to use 'lineinfile' module. In my example below, Ubuntu 18.x no longer has the /etc/rc.local but it still works. See below
1## NOTE : /etc/rc.local doesn't exist in Ubuntu18.x but still runs if executable + has the shebang line
2## See https://www.claudiokuenzler.com/blog/783/ubuntu-18.04-rc.local-file-not-exist-launch-with-systemd-rc-local#.XDYuL88zZTY
3- name: Create executable /etc/rc.local if it doesn't exist
4 lineinfile:
5 dest: /etc/rc.local
6 line: "{{ item }}"
7 create: yes
8 mode: 0755
9 with_items:
10 - '#!/bin/bash'
11 - 'exit 0'