Przewiń do głównej treści

Ansible - instalacja pakietu jeśli nie istnieje

·76 słów·1 min
Michał Kuzdzal
Autor
Michał Kuzdzal
SRE/DevOps. Dziennik pracy: Kubernetes, observability, infrastruktura jako kod i bazy rozproszone.
Spis treści

Exit code przydać nam się mogą w ansiblu do sprawdzania prostych warunków. W tym przypadku do zweryfikowania czy mamy zainstalowany pakiet repozytoriów puppetlabs.

- name: "Check if puppet is installed"  
  shell: dpkg-query -W puppet5-release
  register: is_puppet_installed
  failed_when: no
  changed_when: no
  
- name: "Download puppetlabs package"
  get_url:  
    url: https://apt.puppetlabs.com/puppet5-release-{{   ansible_distribution_release }}.deb
    dest: /tmp/puppet5-release-{{ ansible_distribution_release }}.deb
  when: is_puppet_installed.rc == 1

- name: "Install puppet repository"
  apt: deb="/tmp/puppet5-release-{{ ansible_distribution_release }}.deb"   when: is_puppet_installed.rc == 1

Linki
#

Ansible error handling