Search code examples
ansibleapt

``apt-mark hold`` and ``apt-mark unhold`` with ansible modules


I'm writing my k8s upgrade ansible playbook, and within that I need to do apt-mark unhold kubeadm. Now, I am trying to avoid using the ansible command or shell module to call apt if possible, but the apt hold/unhold command does not seem to be supported by neither package nor apt modules.

Is it possible to do apt-mark hold in ansible without command or shell?


Solution

  • You can use the ansible.builtin.dpkg_selections module for this.

    Note that unhold translates to install in this context.

    - name: Hold kubeadm
      ansible.builtin.dpkg_selections:
        name: kubeadm
        selection: hold
    
    - name: Unhold kubeadm
      ansible.builtin.dpkg_selections:
        name: kubeadm
        selection: install