Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

403
Visualizações
Hold multiple packages using Ansible

I am trying to hold multiple packages using ansible-playbook but it doesn't work with me.

Using the below code it holds the first package then un-hold it then hold the second package

Here is my code

- name: Prevent packages from being upgraded
  dpkg_selections:
    name: "{{ item }}"
    selection: hold
  with_items:
    - postgresql
    - docker

Here is the output from the server side while the code executing enter image description here the first line before executing the second line is the output when the first package was hold the third line when the second package was held and it is stoped

I don't understand why the behavior is like that? and how can I hold multiple packages at a time using ansible?

NOTE: I already followed the instruction from Anible doc https://docs.ansible.com/ansible/latest/collections/ansible/builtin/dpkg_selections_module.html Thanks in advance

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Already for performance and resource reasons, providing the packages as list might be better.

- name: Prevent packages from being upgraded
  dpkg_selections:
    name: ['postgresql', 'docker']
    selection: hold

However, your test reported

dpkg: error: unexpected data after package and selection

Therefore it might be that the module can't handle lists, so I had a look into the source dpkg_selections.py. It seems to be a somehow simple wrapper

module.run_command([dpkg, '--set-selections'], data="%s %s" % (name, selection), check_rc=True)

which just provide information for one module. I also assume the module should work with_items, but it seems to be not the case because of your question.

According man pages, the command dpkg itself seems to be able to handle a package list, but provided as character separated value file

dpkg --set-selections < /tmp/pkg_list

with delimiter in the format

postgresql hold
docker hold

A simple workaround could help in your case.

- name: Prevent packages from being upgraded
  shell:
    cmd: |
      dpkg --set-selections << EOF
      postgresql hold
      docker hold
      EOF
    warn: false
    register: result

You may need to implement some error and status handling by yourself, i.e.

changed_when: result.rc ...
failed_when: result.rc ...

Thanks to

  • How to do multiline shell script in Ansible
over 4 years ago · Santiago Trujillo Relatório

0

What about:

- name: Prevent packages from being upgraded
  dpkg_selections:
    name: "{{ item }}"
    selection: hold
  loop:
    - postgresql
    - docker

In my case, the output from the server side after the execution was the full list of packages.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda