Create multiple directories with mode and loop via ansible
I'm trying to play with loop and ask in a playbook to ansible creating multiple directories on a server with specific attributes : mode owner group .
I think i'm close but don't get it working.
I get this error:
Unsupported parameters for (file) module: recursive Supported parameters include: _diff_peek, _original_basename, access_time, access_time_format, attributes, backup, content, delimiter, directory_mode, follow, force, group, mode, modification_time, modification_time_format, owner, path, recurse, regexp, remote_src, selevel, serole, setype, seuser, src, state, unsafe_writes
Any advice would be very appreciated :
Here is the playbook sample :
- name: ansible create directory with_items example
file:
path: "{{ item.dest }}"
mode: "{{item.mode}}"
owner: "{{item.owner}}"
group: "{{item.group}}"
recursive: true
state: directory
loop:
- { dest: '/var/lib/tftpboot/os/uefi/debian11', mode: '0744', owner: 'root', group: 'root' }
- { dest: '/var/lib/tftpboot/os/uefi/ubuntu2004D', mode: '0744', owner: 'root', group: 'root'}
- { dest: '/var/lib/tftpboot/os/uefi/f34w', mode: '0744', owner: 'root', group: 'root'}
- { dest: '/var/lib/tftpboot/os/uefi/f34s', mode: '0744', owner: 'root', group: 'root'}
- { dest: '/srv/nfs/isos', mode: '0744', owner: 'root', group: 'rpcuser'}
- { dest: '/srv/nfs/pxe/debian11', mode: '0744', owner: 'root', group: 'rpcuser'}
- { dest: '/srv/nfs/pxe/ubuntu2004', mode: '0744', owner: 'root', group: 'rpcuser'}
- { dest: '/srv/nfs/pxe/f34w', mode: '0744', owner: 'root', group: 'rpcuser'}
- { dest: '/srv/nfs/pxe/f34s', mode: '0744', owner: 'root', group: 'rpcuser'}
- { dest: '/tmp/debian11', mode: '0744', owner: 'root', group: 'root'}
- { dest: '/tmp/f34w', mode: '0744', owner: 'root', group: 'root'}
- { dest: '/tmp/ubuntu2004D', mode: '0744', owner: 'root', group: 'root'}
Solution 1:
You have a typo in the parameters. The parameter is called recurse
, you've written recursive
.