Skip to content

Commit

Permalink
Pre chaging simulation approach
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsm committed Jul 2, 2024
1 parent 87f5b80 commit ff9ce50
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 90 deletions.
2 changes: 1 addition & 1 deletion roles/grub/templates/grub.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% else %}
{% set paramValPrefix = '' %}
{% endif %}
{{ paramName }}="{{ paramValPrefix }}{{ param.value | aybarsm.helper.flatten_query('name', 'value', '=', ' ') }}"
{{ paramName }}="{{ paramValPrefix }}{{ param.value | aybarsm.helper.to_querystring('name', 'value', '=', ' ') }}"
{% else %}
{{ paramName }}="{{ param.value }}"
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion roles/network_interfaces/templates/network_interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ iface lo inet loopback
{% endif %}
iface {{ iface.name }} {{ addr_family }} {{ ifaceMethod }}
{% if ifaceParams | length > 0 %}
{{ ifaceParams | aybarsm.helper.flatten_query('name', 'value', ' ', '\n') | indent(4, true) }}
{{ ifaceParams | aybarsm.helper.to_querystring('name', 'value', ' ', '\n') | indent(4, true) }}
{% endif %}
{% endif %}

Expand Down
2 changes: 2 additions & 0 deletions roles/package_manager/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ linux_role_package_manager_enabled: false
# Available options: specific, common
linux_package_manager_package_strategy: specific

linux_package_manager_package_simulation: true

linux_package_manager_default: []
linux_package_manager_group: []
linux_package_manager_host: []
Expand Down
13 changes: 0 additions & 13 deletions roles/package_manager/tasks/common.yml

This file was deleted.

11 changes: 11 additions & 0 deletions roles/package_manager/tasks/common_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Manage system packages with common package manager
ansible.builtin.package:
name: "{{ item.name }}"
state: "{{ item.state | default(omit) }}"
use: "{{ item.use | default(omit) }}"
register: linux_package_manager_common_packages_apply
when:
- linux_packages_all | type_debug == 'list'
- linux_packages_all | length > 0
loop: "{{ linux_packages_all }}"
9 changes: 5 additions & 4 deletions roles/package_manager/tasks/deb_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Manage DEB packages via APT
become: true
ansible.builtin.apt:
name: "{{ package_name }}"
name: "{{ item.name }}"
allow_change_held_packages: "{{ item.allow_change_held_packages | default(omit) | bool }}"
allow_downgrade: "{{ item.allow_downgrade | default(omit) | bool }}"
allow_unauthenticated: "{{ item.allow_unauthenticated | default(omit) | bool }}"
Expand All @@ -26,10 +26,11 @@
update_cache_retries: "{{ item.update_cache_retries | default(omit) }}"
update_cache_retry_max_delay: "{{ item.update_cache_retry_max_delay | default(omit) }}"
upgrade: "{{ item.upgrade | default(omit) }}"
vars:
package_name: "{{ item.name + '=' + item.version if 'version' in item else item.name }}"
loop: "{{ linux_package_manager_packages_all }}"
register: linux_package_manager_deb_packages_apply
vars:
__is_simulation: "{{ __linux_package_manager_simulate_packages | default(false) | bool }}"
register: "{{ 'linux_package_manager_deb_packages_' + ('simulate' if __is_simulation else 'simulate') }}"
check_mode: "{{ __is_simulation }}"
when:
- linux_package_manager_packages_all | type_debug == 'list'
- linux_package_manager_packages_all | length > 0
12 changes: 12 additions & 0 deletions roles/package_manager/tasks/deb_simulations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Simulate DEB package install via APT
ansible.builtin.command:
cmd: "apt --simulate install {{ packages | join(' ') }}"
register: linux_package_manager_deb_packages_simulate_install
changed_when: false

- name: Simulate DEB package remove via APT
ansible.builtin.command:
cmd: "apt --simulate remove {{ packages | join(' ') }}"
register: linux_package_manager_deb_packages_simulate_remove
changed_when: false
14 changes: 13 additions & 1 deletion roles/package_manager/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
- linux_role_package_manager_enabled | default(false) | bool
- ansible_os_family | lower == 'debian'

- name: Simulate DEB package tasks (APT)
ansible.builtin.import_tasks:
file: deb_packages.yml
vars:
__linux_package_manager_simulate_packages: true
when:
- linux_role_package_manager_enabled | default(false) | bool
- linux_package_manager_package_strategy | lower == 'specific'
- ansible_os_family | lower == 'debian'
- linux_package_manager_package_simulation | default(true) | bool
- not ansible_check_mode

- name: Import DEB package tasks (APT)
ansible.builtin.import_tasks:
file: deb_packages.yml
Expand All @@ -22,7 +34,7 @@

- name: Import common package manager tasks
ansible.builtin.import_tasks:
file: common.yml
file: common_packages.yml
when:
- linux_role_package_manager_enabled | default(false) | bool
- linux_package_manager_package_strategy | lower == 'common'
13 changes: 7 additions & 6 deletions roles/package_manager/vars/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ __linux_package_manager_package_config:
- ['type', 'equalto', 'package']
- when: "{{ __linux_package_manager_uniques_package | product(['defined']) | list }}"
logic: or
replace_keys:
- before: package
after: name
- before: pkg
after: name
setattr:
- attribute: name
value: package
Expand All @@ -25,13 +30,9 @@ __linux_package_manager_package_config:
- ['name', 'undefined']
- ['pkg', 'defined']
- attribute: state
value: absent
else: present
overwrite: true
value: present
when:
- ['autoremove', 'defined']
- ['autoremove', 'true']
logic: and
- ['state', 'undefined']
splitattr:
- srcAttr: name
dstAttr: version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ linux_role_posix_sysctl_enabled: false
linux_posix_sysctl_default: []
linux_posix_sysctl_group: []
linux_posix_sysctl_host: []
# The combination strategy below is highly nested hierarchy compliant and recommended (Example provided below)
# The combination strategy below is highly nested hierarchy compliant and recommended.
# linux_posix_sysctl_host > linux_posix_sysctl_group > linux_posix_sysctl_default
linux_posix_sysctl_all: "{{ (linux_posix_sysctl_host + linux_posix_sysctl_group + linux_posix_sysctl_default) | unique(attribute='name') }}"
6 changes: 4 additions & 2 deletions roles/posix/tasks/sysctl.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# TODO: Implement handlers for sysctl
- name: Deploy posix sysctl settings
ansible.posix.sysctl:
name: "{{ item.name }}"
Expand All @@ -8,7 +9,8 @@
state: "{{ item.state | default(omit) }}"
sysctl_file: "{{ item.sysctl_file | default(omit) }}"
sysctl_set: "{{ item.sysctl_set | default(omit) | bool }}"
loop: "{{ linux_posix_sysctl_all }}"
register: linux_posix_sysctl_deploy
when:
- linux_posix_sysctl_all | linux_type_debug == 'list'
- linux_posix_sysctl_all | type_debug == 'list'
- linux_posix_sysctl_all | length > 0
loop: "{{ linux_posix_sysctl_all }}"
8 changes: 4 additions & 4 deletions roles/proxmox/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
linux_role_proxmox_enabled: false

linux_proxmox_default: []
linux_proxmox_group: []
linux_proxmox_host: []
linux_proxmox_default: {}
linux_proxmox_group: {}
linux_proxmox_host: {}

linux_proxmox_all: "{{ linux_proxmox_default + linux_proxmox_group + linux_proxmox_host }}"
linux_proxmox_all: "{{ linux_proxmox_default | combine(linux_proxmox_group, linux_proxmox_host) }}"
7 changes: 7 additions & 0 deletions roles/proxmox/tasks/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Debug
ansible.builtin.debug:
msg:
linux_proxmox_role_repos: "{{ linux_proxmox_role_repos }}"
linux_proxmox_all: "{{ linux_proxmox_all }}"
delegate_to: localhost
4 changes: 4 additions & 0 deletions roles/proxmox/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Include Debug Tasks
ansible.builtin.import_tasks:
file: debug.yml
23 changes: 1 addition & 22 deletions roles/proxmox/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,4 @@ linux_proxmox_role_repos:
filename: ceph
ceph_reef_no_subscription:
repo: "deb {{ linux_proxmox_repo_url_no_subscription }}/ceph-reef {{ ansible_distribution_release }} no-subscription"
filename: ceph

# '<role_name> <repo_prefix> <filename>'
# if <repo_prefix> is empty, there won't be any prefix at the end of the repo line
# (i.e. /pve bookworm pve-enterprise vs /ceph-pacific bookworm enterprise)
# if <filename> is empty, it will be the same as <repo_prefix>-<subscription_type>
# (i.e. pve-no-subscription vs ceph)
# linux_proxmox_role_repos:
# - ['pve', 'pve-']
# - ['pbs', 'pbs-']
# - ['pmg', 'pmg-']
# - ['ceph-reef', '', 'ceph']
# - ['ceph-quincy', '', 'ceph']
# - ['ceph-pacific', '', 'ceph']

# linux_proxmox_role_repos:
# pve: ['pve-']
# pbs: ['pbs-']
# pmg: ['pmg-']
# ceph_reef: ['ceph-reef', '', 'ceph']
# ceph_quincy: ['ceph-quincy', '', 'ceph']
# ceph_pacific: ['ceph-pacific', '', 'ceph']
filename: ceph
35 changes: 0 additions & 35 deletions roles/systemd/defaults/network.yml

This file was deleted.

0 comments on commit ff9ce50

Please sign in to comment.