首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ansible 2.4如果已经安装了"with_item“循环和"when”条件,如何跳过apt包的安装

ansible 2.4如果已经安装了"with_item“循环和"when”条件,如何跳过apt包的安装
EN

Stack Overflow用户
提问于 2019-01-23 23:47:22
回答 2查看 1.2K关注 0票数 0
代码语言:javascript
复制
i would like please to know if there is a way in a loop with_item.

如果已经安装了带有"when“条件的apt依赖项,则检查并跳过安装

代码语言:javascript
复制
if im adding the "when" condition in the end of the with_item list , its look like the condition check all the list instead of checking just the relevant - in this example python2 

- name: check if python already installed
  shell: dpkg-query -W python2.7
  register: check_python2
  ignore_errors: True


- name: Install apt dependencies
  apt:
    name: "{{item.name}}{{item.version}}"
    state: present
    allow_unauthenticated: yes
    force: yes
  with_items:
    - { name: 'python2.7', version: '' }
    - { name: 'ruby', version: '' }
    - { name: 'postgresql-9.5', version: '' }
    - { name: 'postgresql-contrib-9.5', version: '' }
    - { name: 'libpq-dev', version: '' }
    - { name: 'nodejs', version: '=9.*' }
    - { name: 'python-setuptools', version: '' }
    - { name: 'python-pip', version: '' }
    - { name: 'python-pkg-resources', version: '' }
    - { name: 'sshpass', version: '' }
    - { name: 'zip', version: '' }
    - { name: 'mongodb-org', version: '=4.0.0' }
    - { name: 'libfontconfig', version: '' }
    - { name: 'ntp', version: '' }
    - { name: 'fio', version: '' }
  when: check_python2.rc != 0
  when: check_ruby.rc != 0

如何添加"when“条件来仅检查正确的依赖项

我想检查所有的依赖关系:

如果其中一个没有安装,请安装它们,否则跳过

EN

回答 2

Stack Overflow用户

发布于 2019-01-24 17:52:45

我不确定我是否理解了这个问题,你是指"check_python2.rc != 0“和"check_ruby.rc != 0”这两个条件吗?

代码语言:javascript
复制
when: check_python2.rc != 0 and check_ruby.rc != 0
票数 0
EN

Stack Overflow用户

发布于 2019-01-24 23:04:41

代码语言:javascript
复制
- hosts: all:!
  gather_facts: False
  vars:
    packages:
      - python2.7
      - ruby
      - postgresql-9.5
      - postgresql-contrib-9.5
      - libpq-dev
      - nodejs
      - python-setuptools
      - python-pip
      - python-pkg-resources
      - sshpass
      - zip
      - mongodb-org=4.0.0    
      - libfontconfig
      - ntp
      - fio

  tasks:
    - name: "Install dependencies"
      become: yes
      allow_unauthenticated: yes
      force: yes
      apt:
        pkg: "{{ packages }}"
        state: present
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54330917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档