如何在 SUSE 类工作站(如 SUSE Linux Enterprise Server 和 openSUSE)上安装最新版的 Google Chrome Stable?以下是一个完整的指南,涵盖从添加 GPG 密钥、设置 Google 仓库到安装软件的全过程。

使用 Ansible 在 SUSE 类系统中安装 Google Chrome

任务步骤

  1. 添加 Google Chrome 的 GPG 密钥 ⇒ ansible.builtin.rpm_key
  2. 添加 Google Chrome 仓库 ⇒ community.general.zypper_repository
  3. 刷新 zypper 缓存并安装 Google Chrome ⇒ community.general.zypper

详细步骤

  1. 下载仓库的 GPG 签名密钥 使用 ansible.builtin.rpm_key 模块。此加密密钥用于验证软件包和仓库的真实性,确保软件与 Google 发布的版本一致。
  2. 将 Google Chrome 仓库添加到系统中 使用 community.general.zypper_repository 模块。这是额外的软件源,系统包管理器(如 zypper)会从此处获取软件。
  3. 刷新 zypper 缓存并安装 Google Chrome 使用 community.general.zypper 模块。

参数说明

  • rpm_key
  • key(字符串):仓库 GPG 签名密钥的 URL 或密钥 ID。
  • state(字符串):present 或 absent,确保密钥存在于系统中。
  • zypper_repository
  • name(字符串):仓库名称。
  • description(字符串):仓库的描述。
  • repo(字符串):仓库的 URL。
  • auto_import_keys(布尔值):是否自动导入 GPG 密钥。
  • state(字符串):present 或 absent,确保仓库存在于系统中。
  • runrefresh(布尔值):是否在添加仓库后立即刷新缓存。
  • enable(布尔值):是否启用该仓库。
  • zypper
  • name(字符串):软件包名称(此处为 Google Chrome)。
  • state(字符串):latest、present 或 absent,确保软件包安装到最新版本。
  • update_cache(布尔值):是否在安装前刷新 zypper 缓存,确保下载最新版本的软件包。

示例代码

以下是一个 Ansible Playbook,用于在 SUSE 类系统中安装 Google Chrome。

文件名:install_chrome_suse.yml

---
- name: 安装 Google Chrome
  hosts: all
  become: true
  tasks:
    - name: 添加 rpm 签名密钥
      ansible.builtin.rpm_key:
        key: "https://dl.google.com/linux/linux_signing_key.pub"
        state: present

    - name: 添加 Google Chrome 仓库
      community.general.zypper_repository:
        name: google-chrome
        description: "Google Chrome 仓库"
        repo: "http://dl.google.com/linux/chrome/rpm/stable/x86_64"
        auto_import_keys: true
        state: present
        runrefresh: true
        enable: true

    - name: 安装 Google Chrome
      community.general.zypper:
        name: "google-chrome-stable"
        state: latest
        update_cache: true

执行命令

$ ansible-playbook -i suse/inventory install_chrome_suse.yml

执行结果

PLAY [安装 Google Chrome] *******************************************************

TASK [Gathering Facts] ******************************************************
ok: [suse.example.com]

TASK [添加 rpm 签名密钥] ******************************************************
changed: [suse.example.com]

TASK [添加 Google Chrome 仓库] ***********************************************
changed: [suse.example.com]

TASK [安装 Google Chrome] ****************************************************
changed: [suse.example.com]

PLAY RECAP *******************************************************************
suse.example.com           : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

安装前验证

$ ssh devops@suse.example.com
devops@suse:~> sudo su -
suse:~ # zypper se -i google-chrome-stable
Loading repository data...
Warning: Repository 'openSUSE-Leap-42.3-Update' appears to be outdated. Consider using a different mirror or server.
Warning: Repository 'openSUSE-Leap-42.3-Update-Non-Oss' appears to be outdated. Consider using a different mirror or server.
Reading installed packages...
No matching items found.
suse:~ # zypper repos
Repository priorities are without effect. All enabled repositories share the same priority.
# | Alias                             | Name                             | Enabled | GPG Check | Refresh
--+-----------------------------------+----------------------------------+---------+-----------+---------
1 | openSUSE-Leap-42.3-Non-Oss        | openSUSE-Leap-42.3-Non-Oss       | Yes     | (r ) Yes  | No     
2 | openSUSE-Leap-42.3-Oss            | openSUSE-Leap-42.3-Oss           | Yes     | (r ) Yes  | No     
3 | openSUSE-Leap-42.3-Update         | openSUSE-Leap-42.3-Update        | Yes     | (r ) Yes  | No     
4 | openSUSE-Leap-42.3-Update-Non-Oss | openSUSE-Leap-42.3-Update-Non-Oss | Yes     | (r ) Yes  | No

安装后验证

$ ssh devops@suse.example.com
devops@suse:~> sudo su -
suse:~ # zypper se -i google-chrome-stable
Loading repository data...
Warning: Repository 'openSUSE-Leap-42.3-Update' appears to be outdated. Consider using a different mirror or server.
Warning: Repository 'openSUSE-Leap-42.3-Update-Non-Oss' appears to be outdated. Consider using a different mirror or server.
Reading installed packages...
S  | Name                 | Summary       | Type   
---+----------------------+---------------+--------
i+ | google-chrome-stable | Google Chrome | package
suse:~ # zypper repos
Repository priorities are without effect. All enabled repositories share the same priority.
# | Alias                             | Name                             | Enabled | GPG Check | Refresh
--+-----------------------------------+----------------------------------+---------+-----------+---------
1 | google-chrome                     | google-chrome repository        | Yes     | (r ) Yes  | Yes    
2 | openSUSE-Leap-42.3-Non-Oss        | openSUSE-Leap-42.3-Non-Oss      | Yes     | (r ) Yes  | No     
3 | openSUSE-Leap-42.3-Oss            | openSUSE-Leap-42.3-Oss           | Yes     | (r ) Yes  | No     
4 | openSUSE-Leap-42.3-Update         | openSUSE-Leap-42.3-Update        | Yes     | (r ) Yes  | No     
5 | openSUSE-Leap-42.3-Update-Non-Oss | openSUSE-Leap-42.3-Update-Non-Oss | Yes     | (r ) Yes  | No     
suse:~ # zypper se -s google-chrome-stable
Loading repository data...
Warning: Repository 'openSUSE-Leap-42.3-Update' appears to be outdated. Consider using a different mirror or server.
Warning: Repository 'openSUSE-Leap-42.3-Update-Non-Oss' appears to be outdated. Consider using a different mirror or server.
Reading installed packages...
S  | Name                 | Type    | Version        | Arch   | Repository              
---+----------------------+---------+----------------+--------+-------------------------
i+ | google-chrome-stable | package | 94.0.4606.81-1 | x86_64 | google-chrome repository

通过以上步骤,您可以在 SUSE 类系统中使用 Ansible 的 zypper 模块轻松安装 Google Chrome,并确保其来自官方的可信源。