mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
refactor: improve support for ostree systems
The dependency on `ansible.utils.update_fact` is causing issue with
some users who now must install that collection in order to run
the role, even if they do not care about ostree.
The fix is to stop trying to set `ansible_facts.pkg_mgr`, and instead
force the use of the ostree package manager with the `package:` module
`use:` option. The strategy is - on ostree systems, set the flag
`__$ROLENAME_is_ostree` if the system is an ostree system. The flag
will either be undefined or `false` on non-ostree systems.
Then, change every invocation of the `package:` module like this:
```yaml
- name: Ensure required packages are present
package:
name: "{{ __$ROLENAME_packages }}"
state: present
use: "{{ (__$ROLENAME_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
```
This should ensure that the `use:` parameter is not used if the system
is non-ostree. The goal is to make the ostree support as unobtrusive
as possible for non-ostree systems.
The user can also set `__$ROLENAME_is_ostree: true` in the inventory or play
if the user knows that ostree is being used and wants to skip the check.
Or, the user is concerned about the performance hit for ostree detection
on non-ostree systems, and sets `__$ROLENAME_is_ostree: false` to skip
the check.
The flag `__$ROLENAME_is_ostree` can also be used in the role or tests to
include or exclude tasks from being run on ostree systems.
This fix also improves error reporting in the `get_ostree_data.sh` script
when included roles cannot be found.
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
This commit is contained in:
parent
c7a31e7079
commit
0c590cdf5a
34 changed files with 111 additions and 55 deletions
|
|
@ -31,6 +31,8 @@
|
|||
package:
|
||||
name: "{{ network_packages }}"
|
||||
state: present
|
||||
use: "{{ (__network_is_ostree | d(false)) |
|
||||
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
|
||||
when:
|
||||
- not network_packages is subset(ansible_facts.packages.keys())
|
||||
register: __network_package_install
|
||||
|
|
@ -41,6 +43,8 @@
|
|||
- NetworkManager
|
||||
- nmstate
|
||||
state: present
|
||||
use: "{{ (__network_is_ostree | d(false)) |
|
||||
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
|
||||
when:
|
||||
- network_state is defined
|
||||
- ansible_distribution == 'Fedora' and
|
||||
|
|
@ -53,6 +57,8 @@
|
|||
name:
|
||||
- python3-libnmstate
|
||||
state: present
|
||||
use: "{{ (__network_is_ostree | d(false)) |
|
||||
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
|
||||
when:
|
||||
- network_state is defined
|
||||
- ansible_distribution == 'Fedora' and
|
||||
|
|
|
|||
|
|
@ -7,23 +7,17 @@
|
|||
difference(ansible_facts.keys() | list) | length > 0
|
||||
no_log: true
|
||||
|
||||
- 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 __network_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:
|
||||
__network_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
|
||||
|
||||
- name: Check which services are running
|
||||
service_facts:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue