variables question

What is the proper way for me to leave certain variables blank within a play? Right now if I run i get errors back because all variables are not used in each array. The first 2 permission_vars are directly from the win_acl documentation page.

https://docs.ansible.com/ansible/latest/modules/win_acl_module.html#win-acl-module

  • name: Restrict write and execute access to user
    win_acl:
    user: “{{ item.user }}”
    path: “{{ item.user }}”
    type: “{{ item.type }}”
    rights: “{{ item.rights }}”
    state: “{{ item.state }}”
    inherit: “{{ item.inherit }}”
    propagation: “{{ item.propagation }}”
    with_items:
  • “{{ permission_vars }}”

permission_vars:

  • { user: ‘Fed-Phil’, path: ‘C:\Important\Executable.exe’, type: ‘deny’, rights: ‘ExecuteFile,Write’}
  • { user: ‘BUILTIN\Users’, path: ‘HKCU:\Bovine\Key’, type: ‘allow’, rights: ‘EnumerateSubKeys’, state: ‘present’, inherit: ‘Container, ObjInherit’, propagation: ‘none’}

You want to use the default[1] filter combined with omit[2], e.g.

`

  • win_acl:
    user: “{{ item.user }}”
    path: “{{ item.path }}”
    type: “{{ item.type }}”
    rights: “{{ item.rights }}”
    state: “{{ item.state|default(‘present’) }}”
    inherit: “{{ item.inherit|default(omit) }}”
    propagation: “{{ item.propagation|default(omit) }}”
    with_items:
  • user: Fed-Phil
    path: C:\Important\Executable.exe
    type: deny
    rights: ExecuteFile,Write
  • user: BUILTIN\Users
    path: HKCU:\Bovine\Key
    type: allow
    rights: EnumerateSubKeys
    state: present
    inherit: Container, ObjInherit
    propagation: ‘none’
    `

Here’s what the above means

  • state will use the item value if defined otherwise will use ‘present’
  • inherit and propagation will use the item value if defined otherwise will be set to omit

What omit does is to not pass any value to the module, similar to not specifying that option manually.

Thanks

Jordan

[1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#defaulting-undefined-variables
[2] https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#omitting-parameters

Thank you Jordan