Skip to content

Commit

Permalink
Force to install latest required packages on Photon OS
Browse files Browse the repository at this point in the history
Signed-off-by: Qi (Keira) Zhang <qi-keira.zhang@broadcom.com>
  • Loading branch information
keirazhang committed Jun 21, 2024
1 parent 0eaba26 commit 5b97d8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
6 changes: 3 additions & 3 deletions linux/setup/reconfig_existing_guest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
vars:
check_update_cmd: "tdnf makecache"

- name: "Install 'gawk', 'python3-rpm', 'tar' on VMware Photon OS"
- name: "Install 'sudo', 'gawk', 'python3-rpm', 'tar' on VMware Photon OS"
include_tasks: ../utils/install_uninstall_package.yml
vars:
package_list: ["gawk", "python3-rpm", "tar"]
package_state: "present"
package_list: ["sudo", "gawk", "python3-rpm", "tar"]
package_state: "latest"

- name: "Reconfigure {{ guest_os_ansible_distribution }}"
when: guest_os_family == "Suse"
Expand Down
14 changes: 7 additions & 7 deletions linux/setup/test_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
include_tasks: ../utils/get_linux_system_info.yml
when: guest_os_system_info_retrieved is undefined or not guest_os_system_info_retrieved

- name: "Take a base snapshot if it does not exist"
include_tasks: create_base_snapshot.yml
when: not (base_snapshot_exists | bool)

- name: "Get VMware Tools version and build"
include_tasks: ../utils/get_guest_ovt_version_build.yml
when:
Expand All @@ -52,12 +56,11 @@
- vmtools_is_running | bool
- guestinfo_gathered is undefined or not guestinfo_gathered

- name: "Take a base snapshot if it does not exist"
include_tasks: create_base_snapshot.yml
when: not (base_snapshot_exists | bool)

# Hit issue in Ubuntu 22.04 casually: Temporary failure in name resolution. Restarting servcie can fix it
- name: "Check if it needs to restart systemd-resolved or not to get DNS servers"
when:
- guest_os_ansible_distribution == "Ubuntu"
- guest_os_ansible_distribution_ver == "22.04"
block:
- name: "Get DNS servers"
ansible.builtin.command: "resolvectl status"
Expand All @@ -71,6 +74,3 @@
service_enabled: true
service_state: "restarted"
when: dns_servers_output.stdout.find("DNS Servers:") == -1
when:
- guest_os_ansible_distribution == "Ubuntu"
- guest_os_ansible_distribution_ver == "22.04"
33 changes: 18 additions & 15 deletions linux/utils/install_uninstall_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@
ansible.builtin.set_fact:
package_manage_list: []

- name: "Get installed packages on {{ guest_os_ansible_distribution }}"
include_tasks: get_installed_packages.yml

- name: "Set fact of packages which needs to be installed"
ansible.builtin.set_fact:
package_manage_list: "{{ package_list | difference(guest_installed_packages) }}"
package_manage_op: "Install"
when: package_state in ['installed', 'present']

- name: "Set fact of packages which needs to be installed with latest version"
ansible.builtin.set_fact:
package_manage_list: "{{ package_list }}"
package_manage_op: "Install latest"
when: package_state in ['latest']
when: package_state == 'latest'

- name: "Set fact of packages which needs to be uninstalled"
ansible.builtin.set_fact:
package_manage_list: "{{ package_list | select('in', guest_installed_packages) }}"
package_manage_op: "Uninstall"
when: package_state in ['absent', 'removed']
- name: "Get packages to be installed or uninstalled"
when: package_state != 'latest'
block:
- name: "Get installed packages on {{ guest_os_ansible_distribution }}"
include_tasks: get_installed_packages.yml

- name: "Set fact of packages which needs to be installed"
ansible.builtin.set_fact:
package_manage_list: "{{ package_list | difference(guest_installed_packages) }}"
package_manage_op: "Install"
when: package_state in ['installed', 'present']

- name: "Set fact of packages which needs to be uninstalled"
ansible.builtin.set_fact:
package_manage_list: "{{ package_list | select('in', guest_installed_packages) }}"
package_manage_op: "Uninstall"
when: package_state in ['absent', 'removed']

- name: "Display the pacakge list and operation"
ansible.builtin.debug:
Expand Down

0 comments on commit 5b97d8a

Please sign in to comment.