如果已经安装,则跳过软件包下载

时间:2018-10-24 12:15:00

标签: ansible apt deb

我正在使用ansible安装一个deb软件包,并且如果该软件包已经安装,我不想下载远程文件。目前,我正在这样做:

- name: Check if elasticsearch installed
  become: true
  stat: path=/etc/elasticsearch/elasticsearch.yml
  register: st

- name: Install elasticsearch
  become: yes
  apt:
    deb: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.12.deb
    update_cache: true
    state: present
  when: not st.stat.exists

如果已经安装了deb软件包,是否有更好的方法跳过下载?

1 个答案:

答案 0 :(得分:1)

您将希望package_facts,或者当然要欺骗并掏空类似command: dpkg --search elasticsearch的东西

- name: gather installed packages
  package_facts:
- name: Install elasticsearch
  when: elasticsearch not in ansible_facts.packages

除非您的问题是当可能不是通过dpkg手动安装了elasticsearch时如何执行此操作,否则您的stat:register:方法是明智的。您甚至可能要根据自己的情况,使用with_items:检查文件可能已安装的几个位置

相关问题