From 181c9de09bf5cc0914ce18d2ae00ae2aae66d490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A4=D1=91?= =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=BE=D0=B2?= Date: Tue, 8 Oct 2024 00:38:24 +0300 Subject: [PATCH] working version --- roles/proxmox-upgrade/defaults/main.yml | 4 +- .../tasks/check-new-configs.yml | 2 +- roles/proxmox-upgrade/tasks/main.yml | 37 +++-- roles/proxmox-upgrade/tasks/prepare.yml | 13 ++ .../tasks/upgrade-pve-Debian10.yml | 151 +++++++++--------- roles/proxmox-upgrade/tasks/upgrade-pve.yml | 14 +- roles/proxmox-upgrade/vars/Debian-10.yml | 2 +- 7 files changed, 126 insertions(+), 97 deletions(-) diff --git a/roles/proxmox-upgrade/defaults/main.yml b/roles/proxmox-upgrade/defaults/main.yml index c9bd660..6eb5868 100755 --- a/roles/proxmox-upgrade/defaults/main.yml +++ b/roles/proxmox-upgrade/defaults/main.yml @@ -9,7 +9,7 @@ shutdown_vms: true use_enterprise_repos: false # download created backups? (boolean) -download_backups: true +download_backups: false # where to save backups? backup_path: "/var/backups" @@ -18,7 +18,7 @@ backup_path: "/var/backups" proxmox_pveversion: "/usr/bin/pveversion" proxmox_backup_manager: "/usr/sbin/proxmox-backup-manager" proxmox_qm_manager: "/usr/sbin/qm" -proxmox_pve_min_version: "7.4-15" +proxmox_pve_min_version: "7.4-25" proxmox_pbs_min_version: "2.4.2" proxmox_get_vms_cmd: "qm list |grep running |awk '{print $1}'" proxmox_shutdown_vms_opts: "--forceStop 1" diff --git a/roles/proxmox-upgrade/tasks/check-new-configs.yml b/roles/proxmox-upgrade/tasks/check-new-configs.yml index 5938168..308605d 100755 --- a/roles/proxmox-upgrade/tasks/check-new-configs.yml +++ b/roles/proxmox-upgrade/tasks/check-new-configs.yml @@ -3,7 +3,7 @@ ansible.builtin.find: path: /etc patterns: '*.dpkg-dist' - recurse: yes + recurse: true register: dpkg_dist_files - name: please check following new configuration files and apply your changes, files could be deleted after that. diff --git a/roles/proxmox-upgrade/tasks/main.yml b/roles/proxmox-upgrade/tasks/main.yml index 343ba4d..c040f34 100755 --- a/roles/proxmox-upgrade/tasks/main.yml +++ b/roles/proxmox-upgrade/tasks/main.yml @@ -4,17 +4,6 @@ msg: "Server is already on newest version, stopping here!" when: ansible_distribution_release == proxmox_newest_deb_relase -- name: include OS specific variables - ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}" - vars: - params: - files: - - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" - paths: - - "vars" - tags: - - always - - name: gather facts and check prerequisites ansible.builtin.include_tasks: file: prepare.yml @@ -28,7 +17,31 @@ tags: - backup -- name: perform tasks for Proxmox Virtual Environment Server +- name: perform tasks for Proxmox Virtual Environment Server v.6 + ansible.builtin.include_tasks: + file: upgrade-pve-Debian10.yml + when: is_pve_role and ansible_distribution_release == "buster" + tags: + - backup + +# - name: Force ansible to regather facts for distribution +# ansible.builtin.setup: +# filter: +# - 'ansible_distribution' +# - 'ansible_distribution_release' +# - 'ansible_distribution_major_version' +# when: is_pve_role +# tags: +# - backup + +- name: Print all available facts + ansible.builtin.debug: + var: ansible_distribution_release +- name: Print all available facts + ansible.builtin.debug: + var: ansible_distribution_major_version + +- name: perform tasks for Proxmox Virtual Environment Server v.7 ansible.builtin.include_tasks: file: upgrade-pve.yml when: is_pve_role diff --git a/roles/proxmox-upgrade/tasks/prepare.yml b/roles/proxmox-upgrade/tasks/prepare.yml index d1958f7..d6e5e09 100755 --- a/roles/proxmox-upgrade/tasks/prepare.yml +++ b/roles/proxmox-upgrade/tasks/prepare.yml @@ -37,3 +37,16 @@ ansible.builtin.fail: msg: Stopping because there is not enough free space! There should be at least 5GB free of space. when: space_free_gb > '5' + +- name: "Ensure /etc/network/interfaces contains 'hwaddress'" + command: grep hwaddress /etc/network/interfaces + register: macaddr + ignore_errors: true + changed_when: false + +- name: Write mac-address in file + ansible.builtin.lineinfile: + path: /etc/network/interfaces + insertafter: 'gateway' + line: ' hwaddress {{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}' + when: macaddr.rc == 1 diff --git a/roles/proxmox-upgrade/tasks/upgrade-pve-Debian10.yml b/roles/proxmox-upgrade/tasks/upgrade-pve-Debian10.yml index 31b3cac..68902b7 100755 --- a/roles/proxmox-upgrade/tasks/upgrade-pve-Debian10.yml +++ b/roles/proxmox-upgrade/tasks/upgrade-pve-Debian10.yml @@ -1,93 +1,92 @@ --- -- name: remove pve-enterprise subscription repo - ansible.builtin.file: - path: "{{ proxmox_pve_enterprise_list }}" - state: absent - when: use_enterprise_repos == false +- name: perform tasks for Proxmox Virtual Environment 6 + block: + - name: include OS specific variables + ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}" + vars: + params: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + paths: + - "vars" -- name: make sure that pve-no-subscription repos are active - ansible.builtin.apt_repository: - repo: "{{ item.line }}" - state: present - update_cache: false - loop: "{{ __deb_proxmox_pve_repos | selectattr('release', '==', ansible_distribution_release) }}" + - name: remove pve-enterprise subscription repo + ansible.builtin.file: + path: "{{ proxmox_pve_enterprise_list }}" + state: absent + when: use_enterprise_repos == false -- name: Update packages on Debian 10 - ansible.builtin.apt: - name: "*" - state: latest - update_cache: true - notify: - - reboot server + - name: make sure that pve-no-subscription repos are active + ansible.builtin.apt_repository: + repo: "{{ item.line }}" + state: present + update_cache: false + loop: "{{ __deb_proxmox_pve_repos | selectattr('release', '==', ansible_distribution_release) }}" -- name: flush handlers to reboot instantly - ansible.builtin.meta: flush_handlers + - name: Update packages on Debian 10 + ansible.builtin.apt: + name: "*" + state: latest + update_cache: true + notify: + - reboot server -- name: create backup of configuration - community.general.archive: - path: /etc - dest: "{{ backup_path }}proxmox-pve-backup-{{ ansible_date_time.date }}.tar.gz" - mode: 600 - format: gz - tags: - - backup + - name: flush handlers to reboot instantly + ansible.builtin.meta: flush_handlers -- name: get running virtual maschines - ansible.builtin.shell: - cmd: "{{ proxmox_get_vms_cmd }}" - register: proxmox_running_vms_info - changed_when: false + - name: create backup of configuration + community.general.archive: + path: /etc + dest: "{{ backup_path }}proxmox-pve-backup-{{ ansible_date_time.date }}.tar.gz" + mode: 600 + format: gz + tags: + - backup -- name: shutting down virtual maschines - ansible.builtin.command: - cmd: "{{ proxmox_qm_manager }} shutdown {{ item }} {{ proxmox_shutdown_vms_opts }}" - loop: "{{ proxmox_running_vms_info.stdout_lines }}" - when: shutdown_vms + - name: get running virtual maschines + ansible.builtin.shell: + cmd: "{{ proxmox_get_vms_cmd }}" + register: proxmox_running_vms_info + changed_when: false -- name: update repos - ansible.builtin.include_tasks: - file: update-repos.yml + - name: shutting down virtual maschines + ansible.builtin.command: + cmd: "{{ proxmox_qm_manager }} shutdown {{ item }} {{ proxmox_shutdown_vms_opts }}" + loop: "{{ proxmox_running_vms_info.stdout_lines }}" + when: shutdown_vms -- name: Update packages to Debian 11 - ansible.builtin.apt: - name: "*" - state: latest - update_cache: true - notify: - - reboot server + - name: update repos + ansible.builtin.include_tasks: + file: update-repos.yml -- name: flush handlers to reboot instantly - ansible.builtin.meta: flush_handlers + - name: Fix problem upgrade PVE + ansible.builtin.lineinfile: + path: /usr/share/proxmox-ve/pve-apt-hook + search_string: "$cleanup->(0, 1);" + line: "# $cleanup->(0, 1);" -# - name: Exit if nothing to upgrade -# fail: msg="Only manual upgrade!" + - name: Dist-Upgrade Proxmox Virtual Environment 6 to 7 + ansible.builtin.apt: + update_cache: true + upgrade: dist + force: true + notify: + - reboot server -- name: Upgrade Proxmox Virtual Environment Server on Debian 10 - ansible.builtin.apt: - update_cache: true - upgrade: dist - force: true - notify: - - reboot server + - name: flush handlers to reboot instantly + ansible.builtin.meta: flush_handlers -- name: Remove useless packages from the cache - ansible.builtin.apt: - autoclean: true + - name: Force ansible to regather facts for distribution + ansible.builtin.setup: + filter: + - 'ansible_distribution' + - 'ansible_distribution_release' + - 'ansible_distribution_major_version' -- name: Remove dependencies that are no longer required and purge their configuration files - ansible.builtin.apt: - autoremove: true - purge: true - -- name: flush handlers to reboot instantly - ansible.builtin.meta: flush_handlers - -- name: check if proxmox pve role is installed - ansible.builtin.stat: - path: "{{ proxmox_pveversion }}" - register: pve_version_info - tags: - - backup + # - name: Set facts + # ansible.builtin.set_fact: + # ansible_distribution_release: bullseye + # ansible_distribution_major_version: 11 notify: - reboot server diff --git a/roles/proxmox-upgrade/tasks/upgrade-pve.yml b/roles/proxmox-upgrade/tasks/upgrade-pve.yml index 868777c..a9fc647 100755 --- a/roles/proxmox-upgrade/tasks/upgrade-pve.yml +++ b/roles/proxmox-upgrade/tasks/upgrade-pve.yml @@ -1,10 +1,14 @@ --- -- name: perform tasks for Proxmox Virtual Environment +- name: perform tasks for Proxmox Virtual Environment 7 block: - - name: Run upgrade Debian 10 - ansible.builtin.include_tasks: - file: upgrade-pve-Debian10.yml - when: ansible_distribution_release == "buster" + - name: include OS specific variables + ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}" + vars: + params: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + paths: + - "vars" - name: remove pve-enterprise subscription repo ansible.builtin.file: diff --git a/roles/proxmox-upgrade/vars/Debian-10.yml b/roles/proxmox-upgrade/vars/Debian-10.yml index 9280e8e..9b4c01b 100755 --- a/roles/proxmox-upgrade/vars/Debian-10.yml +++ b/roles/proxmox-upgrade/vars/Debian-10.yml @@ -1,5 +1,5 @@ --- -# when Debian 10 (buster) is detected, change repos to Debian 12 (bullseye) +# when Debian 10 (buster) is detected, change repos to Debian 11 (bullseye) __deb_debian_repos: - { "line": "deb http://ftp.ru.debian.org/debian bullseye main contrib",