Skip to content

Commit

Permalink
selinux: turn restorecon call into handler
Browse files Browse the repository at this point in the history
  • Loading branch information
guidograzioli committed Mar 23, 2022
1 parent 83bc70e commit dfaeaca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
10 changes: 6 additions & 4 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
tomcat_uid: 53
tomcat_group: tomcat
tomcat_gid: 53
tomcat_service_name: tomcat
tomcat_home: /opt/apache-tomcat-9.0.50
tasks:
- name: "Check that user account {{ tomcat_user }} was properly created"
user:
Expand Down Expand Up @@ -45,10 +47,10 @@
that:
- ansible_facts is defined
- ansible_facts.services is defined
- ansible_facts.services[tomcat.service.name] is defined
- ansible_facts.services[tomcat.service.name]['state'] is defined
- ansible_facts.services[tomcat.service.name]['state'] == 'running'
- ansible_facts.services[tomcat.service.name]['status'] == 'enabled'
- ansible_facts.services['tomcat.service'] is defined
- ansible_facts.services['tomcat.service']['state'] is defined
- ansible_facts.services['tomcat.service']['state'] == 'running'
- ansible_facts.services['tomcat.service']['status'] == 'enabled'
quiet: true
fail_msg: "Service is not started."

Expand Down
10 changes: 10 additions & 0 deletions roles/jws/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@
- tomcat.service.enabled is defined
- tomcat.service.enabled
listen: "Restart Tomcat service"

- name: Install selinux policy
command: semodule -i jws5-tomcat.pp
args:
chdir: "{{ tomcat.home }}/selinux"
listen: "Selinux policy created"

- name: Apply selinux policy
command: "restorecon -r {{ tomcat.install_dir }}"
listen: "Apply selinux policy"
14 changes: 3 additions & 11 deletions roles/jws/tasks/systemd/selinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@
creates: "{{ tomcat.home }}/selinux/jws5-tomcat.pp"
when:
- not policy_path_selinux.stat.exists
register: policy_created

- name: Install selinux policy
command: semodule -i jws5-tomcat.pp
args:
chdir: "{{ tomcat.home }}/selinux"
when:
- policy_created.changed

- name: Apply selinux policy
command: "restorecon -r {{ tomcat.install_dir }}"
notify:
- "Selinux policy created"
- "Apply selinux policy"
when: archive_path_selinux.stat.exists
2 changes: 1 addition & 1 deletion roles/jws/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ tomcat:
systemd: "{{ tomcat_service_systemd }}"
pidfile: "{{ tomcat_service_systemd_pidfile }}"
type: "{{ tomcat_service_systemd_type }}"
hr_name: "{{ 'Jboss Web Server' if tomcat_install_method in ['rhn_zipfiles','rpm'] else 'Tomcat' }}"
hr_name: "{{ 'Jboss Web Server' if tomcat_install_method in ['rhn_zipfiles','rpm'] else 'Tomcat' }}"

0 comments on commit dfaeaca

Please sign in to comment.