i would like please to know if there is a way in a loop with_item.如果已经安装了带有"when“条件的apt依赖项,则检查并跳过安装
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“条件来仅检查正确的依赖项
我想检查所有的依赖关系:
如果其中一个没有安装,请安装它们,否则跳过
发布于 2019-01-24 17:52:45
我不确定我是否理解了这个问题,你是指"check_python2.rc != 0“和"check_ruby.rc != 0”这两个条件吗?
when: check_python2.rc != 0 and check_ruby.rc != 0发布于 2019-01-24 23:04:41
- 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: presenthttps://stackoverflow.com/questions/54330917
复制相似问题