diff --git a/.ansible-lint b/.ansible-lint index 4d6ee007..96e17227 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -22,5 +22,3 @@ exclude_paths: - examples/roles/ mock_roles: - linux-system-roles.logging -mock_modules: - - ansible.utils.update_fact diff --git a/.ostree/get_ostree_data.sh b/.ostree/get_ostree_data.sh index 7c325241..cec08b0c 100755 --- a/.ostree/get_ostree_data.sh +++ b/.ostree/get_ostree_data.sh @@ -2,7 +2,6 @@ set -euo pipefail -role_collection_dir="${ROLE_COLLECTION_DIR:-fedora/linux_system_roles}" ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}" if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then @@ -29,7 +28,7 @@ if [ "$pkgtype" = testing ]; then fi get_rolepath() { - local ostree_dir role rolesdir roles_parent_dir + local ostree_dir role rolesdir roles_parent_dir coll_path pth ostree_dir="$1" role="$2" roles_parent_dir="$(dirname "$(dirname "$ostree_dir")")" @@ -47,16 +46,22 @@ get_rolepath() { fi done # look elsewhere - if [ -n "${ANSIBLE_COLLECTIONS_PATHS:-}" ]; then - for pth in ${ANSIBLE_COLLECTIONS_PATHS//:/ }; do - rolesdir="$pth/ansible_collections/$role_collection_dir/roles/$role/.ostree" - if [ -d "$rolesdir" ]; then - echo "$rolesdir" - return 0 - fi + coll_path="${ANSIBLE_COLLECTIONS_PATH:-}" + if [ -z "$coll_path" ]; then + coll_path="${ANSIBLE_COLLECTIONS_PATHS:-}" + fi + if [ -n "${coll_path}" ]; then + for pth in ${coll_path//:/ }; do + for rolesdir in "$pth"/ansible_collections/*/*_system_roles/roles/"$role"/.ostree; do + if [ -d "$rolesdir" ]; then + echo "$rolesdir" + return 0 + fi + done done fi - return 1 + 1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH + exit 2 } get_packages() { @@ -75,6 +80,10 @@ get_packages() { roles="$(cat "$rolefile")" for role in $roles; do rolepath="$(get_rolepath "$ostree_dir" "$role")" + if [ -z "$rolepath" ]; then + 1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH + exit 2 + fi get_packages "$rolepath" done fi diff --git a/meta/collection-requirements.yml b/meta/collection-requirements.yml index e22fbe02..0e6f8ea3 100644 --- a/meta/collection-requirements.yml +++ b/meta/collection-requirements.yml @@ -2,5 +2,4 @@ --- collections: - ansible.posix - - ansible.utils - fedora.linux_system_roles diff --git a/roles/rsyslog/tasks/deploy.yml b/roles/rsyslog/tasks/deploy.yml index 2dd54ff0..2ef181ae 100644 --- a/roles/rsyslog/tasks/deploy.yml +++ b/roles/rsyslog/tasks/deploy.yml @@ -5,6 +5,8 @@ package: name: "{{ __rsyslog_packages }}" state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" when: - __rsyslog_packages | length > 0 - not rsyslog_in_image | bool diff --git a/roles/rsyslog/tasks/deploy_nolog.yml b/roles/rsyslog/tasks/deploy_nolog.yml index 64e5dda6..b3aaa240 100644 --- a/roles/rsyslog/tasks/deploy_nolog.yml +++ b/roles/rsyslog/tasks/deploy_nolog.yml @@ -9,6 +9,8 @@ package: name: "{{ __rsyslog_packages }}" state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" when: - __rsyslog_packages | length > 0 - not rsyslog_in_image | bool diff --git a/roles/rsyslog/tasks/main_core.yml b/roles/rsyslog/tasks/main_core.yml index bba6f57a..a54073c4 100644 --- a/roles/rsyslog/tasks/main_core.yml +++ b/roles/rsyslog/tasks/main_core.yml @@ -4,12 +4,10 @@ # if inputs are given and rsyslog_enabled is true, rsyslog.conf will be # overwritten, so no need to reinstall package - name: Reinstall package to restore rsyslog config if purging - vars: - ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree when: - logging_purge_confs | bool | d(false) - not (rsyslog_inputs and __rsyslog_enabled | bool) - - not ansible_facts.pkg_mgr | d() == ostree_pkg_mgr + - not __logging_is_ostree | d(false) block: # it is assumed that the only packages providing config files that might # be modified are the base packages - if this is not so, then additional @@ -25,6 +23,8 @@ package: name: "{{ __rsyslog_base_packages }}" state: absent + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" register: __rsyslog_erased when: __rsyslog_package_status.results | rejectattr('stdout', 'match', '^package .* is not installed') | @@ -37,6 +37,8 @@ if (logging_pki_files | d([]) | length > 0) else []) + (rsyslog_extra_packages | flatten) }}" state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" when: - __rsyslog_enabled | bool or (__rsyslog_erased is success and __rsyslog_erased is changed) @@ -385,9 +387,7 @@ - name: Create or recreate main config file vars: - ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree - is_ostree: "{{ ansible_facts.pkg_mgr | d() == ostree_pkg_mgr }}" - __rsyslog_generate_conf: "{{ is_ostree | + __rsyslog_generate_conf: "{{ (__logging_is_ostree | d(false)) | ternary(true, __rsyslog_enabled and rsyslog_inputs | d([]) | length > 0) }}" when: __rsyslog_generate_conf | bool @@ -397,7 +397,7 @@ paths: "{{ __rsyslog_config_dir }}" patterns: "*.conf" register: __rsyslog_find_result - when: is_ostree | bool + when: __logging_is_ostree | d(false) - name: Get mode of rsyslog.conf if it exists stat: @@ -414,4 +414,4 @@ when: __rsyslog_generate_conf | bool vars: __rsyslog_has_config_files: "{{ __rsyslog_find_result.matched > 0 - if is_ostree else true }}" + if __logging_is_ostree | d(false) else true }}" diff --git a/roles/rsyslog/tasks/set_vars.yml b/roles/rsyslog/tasks/set_vars.yml index dbc28524..0ab977e6 100644 --- a/roles/rsyslog/tasks/set_vars.yml +++ b/roles/rsyslog/tasks/set_vars.yml @@ -7,23 +7,17 @@ when: __logging_required_facts | difference(ansible_facts.keys() | list) | length > 0 -- name: Ensure correct package manager for ostree systems - vars: - ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree - ostree_booted_file: /run/ostree-booted - when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr +- name: Determine if system is ostree and set flag + when: not __logging_is_ostree is defined block: - name: Check if system is ostree stat: - path: "{{ ostree_booted_file }}" + path: /run/ostree-booted register: __ostree_booted_stat - - name: Set package manager to use for ostree - ansible.utils.update_fact: - updates: - - path: ansible_facts.pkg_mgr - value: "{{ ostree_pkg_mgr }}" - when: __ostree_booted_stat.stat.exists + - name: Set flag to indicate system is ostree + set_fact: + __logging_is_ostree: "{{ __ostree_booted_stat.stat.exists }}" - name: Set platform/version specific variables include_vars: "{{ item }}" diff --git a/tests/tests_enabled.yml b/tests/tests_enabled.yml index 64cd1374..fd56451d 100644 --- a/tests/tests_enabled.yml +++ b/tests/tests_enabled.yml @@ -40,9 +40,8 @@ - name: Ensure config file size and counts vars: - ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree __conf_count: 0 - __conf_size: "{{ 'less' if ansible_facts.pkg_mgr | d() == ostree_pkg_mgr + __conf_size: "{{ 'less' if __logging_is_ostree | d(false) else 'more' }}" __conf_files: [] __check_systemctl_status: true diff --git a/tests/tests_purge_reset.yml b/tests/tests_purge_reset.yml index ca98f239..051a788c 100644 --- a/tests/tests_purge_reset.yml +++ b/tests/tests_purge_reset.yml @@ -6,29 +6,25 @@ hosts: all vars: __test_default_files_conf: /etc/rsyslog.d/30-output-files-default_files.conf - ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree tasks: - - name: Ensure correct package manager for ostree systems - vars: - ostree_booted_file: /run/ostree-booted - when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + - name: Determine if system is ostree and set flag + when: not __logging_is_ostree is defined block: - name: Check if system is ostree stat: - path: "{{ ostree_booted_file }}" + path: /run/ostree-booted register: __ostree_booted_stat - - name: Set package manager to use for ostree - ansible.utils.update_fact: - updates: - - path: ansible_facts.pkg_mgr - value: "{{ ostree_pkg_mgr }}" - when: __ostree_booted_stat.stat.exists + - name: Set flag to indicate system is ostree + set_fact: + __logging_is_ostree: "{{ __ostree_booted_stat.stat.exists }}" - name: Ensure rsyslog is installed package: name: rsyslog state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" - name: Create some unowned config files copy: @@ -118,7 +114,7 @@ - name: Ensure config file size and counts vars: __conf_count: 0 - __conf_size: "{{ 'less' if ansible_facts.pkg_mgr | d() == ostree_pkg_mgr + __conf_size: "{{ 'less' if __logging_is_ostree | d(false) else 'more' }}" __check_systemctl_status: true include_tasks: tasks/check_daemon_config_files.yml diff --git a/tests/tests_relp.yml b/tests/tests_relp.yml index 41c06994..d04dbadf 100644 --- a/tests/tests_relp.yml +++ b/tests/tests_relp.yml @@ -89,6 +89,8 @@ package: name: lsof state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" - name: Check lsof outputs for rsyslogd shell: |- diff --git a/tests/tests_remote.yml b/tests/tests_remote.yml index 88f0c838..05ef6c90 100644 --- a/tests/tests_remote.yml +++ b/tests/tests_remote.yml @@ -67,6 +67,8 @@ package: name: lsof state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" - name: Check lsof outputs for rsyslogd shell: |- @@ -191,6 +193,8 @@ package: name: lsof state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" - name: Check lsof outputs for rsyslogd shell: |- diff --git a/tests/tests_server.yml b/tests/tests_server.yml index 64d793dd..a046ff85 100644 --- a/tests/tests_server.yml +++ b/tests/tests_server.yml @@ -85,6 +85,8 @@ package: name: lsof state: present + use: "{{ (__logging_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" - name: Check lsof outputs for rsyslogd shell: |-