diff --git a/defaults/main/0_hardcoded.yml b/defaults/main/0_hardcoded.yml index 1c89b22..a12720a 100644 --- a/defaults/main/0_hardcoded.yml +++ b/defaults/main/0_hardcoded.yml @@ -3,6 +3,7 @@ NONE_VALUES: [none, '', ' '] random_pwd_length: '50' tmp_pwd_file_prefix: '/tmp/.ansibleguy.sw_zoneminder' +zm_php_version_override: '7.4' ZM_HC: packages: @@ -12,7 +13,7 @@ ZM_HC: repo_key: "https://zmrepo.zoneminder.com/{{ ansible_distribution | lower }}/archive-keyring.gpg" repo: "deb https://zmrepo.zoneminder.com/{{ ansible_distribution | lower }}/release {{ ansible_lsb.codename | default('buster') }}/" - php_version: '7.4' + php_version: '{{zm_php_version_override}}' apache: modules: ['ssl', 'headers', 'rewrite', 'http2', 'cgi'] diff --git a/filter_plugins/utils.py b/filter_plugins/utils.py new file mode 100644 index 0000000..48325d1 --- /dev/null +++ b/filter_plugins/utils.py @@ -0,0 +1,64 @@ +from re import sub as regex_replace + + +class FilterModule(object): + + def filters(self): + return { + "safe_key": self.safe_key, + "all_true": self.all_true, + "prepare_letsencrypt": self.prepare_letsencrypt, + "ensure_list": self.ensure_list, + "enmod_list": self.enmod_list, + "mod_list": self.mod_list, + "mgmt_pwd": self.mgmt_pwd, + } + + @staticmethod + def safe_key(key: str) -> str: + return regex_replace(r'[^0-9a-zA-Z\.]+', '', key.replace(' ', '_')) + + @staticmethod + def all_true(data: list) -> bool: + return all(data) + + @staticmethod + def prepare_letsencrypt(site: dict, name: str) -> dict: + domains = [site['domain']] + domains.extend(site['aliases']) + return { + name: { + 'domains': domains, + 'key_size': site['letsencrypt']['key_size'], + 'email': site['letsencrypt']['email'], + 'state': site['state'], + } + } + + @classmethod + def enmod_list(cls, present: list, absent: list) -> str: + absent_list = cls.ensure_list(absent) + return ' '.join([mod for mod in cls.ensure_list(present) if mod not in absent_list]) + + @classmethod + def mod_list(cls, mods: (str, list)) -> str: + return ' '.join(cls.ensure_list(mods)) + + @staticmethod + def ensure_list(data: (str, list)) -> list: + # if user supplied a string instead of a list => convert it to match our expectations + if isinstance(data, list): + return data + + return [data] + + def mgmt_pwd(self, instance: dict) -> str: + return self.fallback(opt1=instance['ansible_pwd'], opt2=instance['root_pwd']) + + @staticmethod + def fallback(opt1: str, opt2: str) -> str: + if opt1 not in [None, '', 'None', 'none', ' ']: + return opt1 + + return opt2 + diff --git a/meta/main.yml b/meta/main.yml index 04f8707..c37515f 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -2,7 +2,7 @@ galaxy_info: author: 'AnsibleGuy ' - namespace: 'ansibleguy' + namespace: 'anon8675309' license: 'MIT' issue_tracker_url: 'https://github.com/ansibleguy/sw_zoneminder/issues' min_ansible_version: '2.14' diff --git a/requirements.yml b/requirements.yml index 65a26bb..d3a1545 100644 --- a/requirements.yml +++ b/requirements.yml @@ -9,6 +9,6 @@ collections: - 'community.crypto' roles: - - src: 'ansibleguy.infra_apache' + - src: 'anon8675309.infra_apache' - src: 'ansibleguy.infra_certs' - src: 'ansibleguy.infra_mariadb' diff --git a/tasks/debian/web.yml b/tasks/debian/web.yml index 5ea3b6a..fbdd4ce 100644 --- a/tasks/debian/web.yml +++ b/tasks/debian/web.yml @@ -2,7 +2,7 @@ - name: ZoneMinder | Webserver | Managing Apache2 ansible.builtin.include_role: - name: ansibleguy.infra_apache + name: anon8675309.infra_apache vars: apache: security: "{{ ZM_CONFIG.apache.security }}"