Trying to use Ansible on a CentOS 7 server to make a directory and sync files into it. That part is working. The problem is I get a 403 Forbidden
error when I try to access them from the browser. I understand that this is a fcontext
problem with SELinux preventing Apache from accessing the files. I thought I had some Ansible code to handle this, but it is not adding the fcontext
. I've manually set the fcontext
on the CLI to make it work. If I remove the directory and run Ansible again, then the directory and files will have the right fcontext
. Trying not to have to manually set the fcontext
when I run this for my production server. Any ideas?
Here's the Ansible code used to set the fcontext
and restorecon
used.
- name: Allow apache to read
sefcontext:
target: "{{ dest_dir }}(/.*)?"
setype: httpd_sys_content_t
state: present
- name: Run restore context to reload selinux
shell: restorecon -iRv "{{ dest_dir }}"