Ansible:除foo,bar

如何编写Ansible剧本来升级除Java和PostgreSQL以外的所有Ubuntu软件包?

通过以下任务,我可以将所有软件包升级到最新版本:

- name: Upgrade all packages to the latest version
  apt:
    name: "*"
    state: latest

是否可以添加要忽略的软件包列表以进行更新/升级?

更新:

感谢弗拉基米尔的回答,我更新了Ansible Playbook:

---
- hosts: DEP-GEOSRV1
  become: yes
  tasks: 

  - name: disable upgrade of java & postgresql
    dpkg_selections:
      name: openjdk-8-jre
      selection: hold
    dpkg_selections:
      name: postgresql-9.3
      selection: hold
    dpkg_selections:
      name: postgresql-server-dev-9.3
      selection: hold

  - name: Upgrade all packages to the latest version except java & postgresql
    apt:
      name: "*"
      force_apt_get: true
      state: latest

不确定此剧本是否正确。有人可以确认吗?

zhuxiwangzhenliang 回答:Ansible:除foo,bar

为特定的软件包设置selection: hold。例如

- dpkg_selections:
    name: openjdk-8-jre
    selection: hold

FWIW。参见example

,

对我来说 dpkg_selections 没有用。

我创建了跟随剧本来解决我的问题。希望对你也有用

- name: get a list of the packages that need update
  shell: apt list --upgradable
  register: list_upgradable

- set_fact:
    upgradable_packages: "{{ list_upgradable.stdout | regex_findall('(^.+)\/',multiline=True) }}"

- apt: 
    name: "{{ item }}"
    state: latest
  when: >
    item != 'linux-base' and 
    item != 'linux-firmware' and 
    item != 'linux-generic' and 
    item != 'linux-headers-generic' and
    item != 'linux-image-generic' and 
    item != 'netplan.io' and 
    item != 'ubuntu-advantage-tools' and 
    item != 'ubuntu-keyring' and 
    item != 'ubuntu-release-upgrader-core' and 
    item != 'ubuntu-server' and 
    item != 'ubuntu-standard'
  loop: "{{ upgradable_packages }}"
本文链接:https://www.f2er.com/3159350.html

大家都在问