Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
As an installer user, plugin snippets will by symlinked
Browse files Browse the repository at this point in the history
fixes: #6213
  • Loading branch information
mikedep333 committed Feb 25, 2020
1 parent ff49789 commit 32d9383
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions roles/pulp-webserver/files/check_snippet.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python

# Checks if the pulp plugin has a specific webserver snippet.

# Usage: check_snippet.py plugin_name snippet_file

# Usage example: check_snippet.py pulp_ansible nginx.conf

# Prints full path to the snippet to stdout and returns rc 0 if found.
# Prints to stderr and returns rc 10 if there are snippets, but not the snippet.
# Prints to stderr and rc 1 if plugin is not found.

import os
import importlib
import sys
webserver_snippets = importlib.import_module(sys.argv[1] + ".app.webserver_snippets")
snippet = os.path.dirname(webserver_snippets.__file__) + "/" + sys.argv[2]
if os.path.exists(snippet):
print(snippet)
else:
sys.stderr.write(sys.argv[1] + " has snippets, but not " + sys.argv[2] + "\n")
sys.exit(10)
28 changes: 28 additions & 0 deletions roles/pulp-webserver/tasks/apache.yml
Expand Up @@ -28,6 +28,34 @@
dest: /etc/httpd/conf.d/pulp-vhost.conf
notify: reload Apache

- name: Create directory for Pulp Apache snippets
file:
path: /etc/httpd/pulp
state: directory

- name: Check installed plugins for Apache snippets
script:
cmd: check_snippet.py {{ item.key | regex_replace("pulp-", "pulp_") | quote }} apache.conf
args:
executable: /usr/local/lib/pulp/bin/python
register: snippets
with_dict: '{{ pulp_install_plugins }}'
failed_when: false
changed_when: false

# FIXME: The ansible output here over the results is very ugly.
# It may be a lot cleaner if we were to use the command module,
# above and/or create a temporary data structure.
- name: Symlink Apache snippets
file:
src: "{{ item.stdout_lines | last }}"
# Note: item.item is pulp_install_plugins
dest: "/etc/httpd/pulp/{{ item.item.key | regex_replace('pulp-', 'pulp_') }}"
state: link
loop: '{{ snippets.results }}'
when: item.rc == 0
notify: reload Apache

- name: Start and enable Apache
systemd:
name: "{{ pulp_webserver_apache_service }}"
Expand Down
23 changes: 23 additions & 0 deletions roles/pulp-webserver/tasks/nginx.yml
Expand Up @@ -36,6 +36,29 @@
dest: /etc/nginx/nginx.conf
notify: reload nginx

- name: Check installed plugins for nginx snippets
script:
cmd: check_snippet.py {{ item.key | regex_replace("pulp-", "pulp_") | quote }} nginx.conf
args:
executable: /usr/local/lib/pulp/bin/python
register: snippets
with_dict: '{{ pulp_install_plugins }}'
failed_when: false
changed_when: false

# FIXME: The ansible output here over the results is very ugly.
# It may be a lot cleaner if we were to use the command module,
# above and/or create a temporary data structure.
- name: Symlink nginx snippets
file:
src: "{{ item.stdout_lines | last }}"
# Note: item.item is pulp_install_plugins
dest: "/etc/nginx/conf.d/{{ item.item.key | regex_replace('pulp-', 'pulp_') }}"
state: link
loop: '{{ snippets.results }}'
when: item.rc == 0
notify: reload nginx

- name: Start and enable Nginx
systemd:
name: nginx
Expand Down

0 comments on commit 32d9383

Please sign in to comment.