--- - name: Check if {{ item }} already exists stat: path: "{{ item }}" register: container_dir - block: - name: Create {{ item }} file: path: "{{ item }}" state: directory owner: "{{ container_user }}" group: "{{ container_group }}" mode: '0770' - name: Modify SELinux contexts for {{ item }} sefcontext: target: "{{ item }}(/.*)?" setype: container_file_t state: present - name: Apply SELinux contexts to {{ item }} shell: cmd: restorecon -r "{{ item }}" when: - not container_dir.stat.exists