ansible 2.4 как пропустить установку пакета apt, если он уже установлен с циклом «with_item» и условием «когда» - PullRequest
0 голосов
/ 23 января 2019
i would like please to know if there is a way in a loop with_item.

чтобы проверить и пропустить установку зависимостей 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

как добавить условие "когда", чтобы проверить только правильные зависимости

Я хотел бы проверить все зависимости:

и если один из них не установлен, установите его, иначе пропустите

Ответы [ 2 ]

0 голосов
/ 24 января 2019
- 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 голосов
/ 24 января 2019

Я не уверен, что понимаю вопрос, вы имеете в виду оба условия "check_python2.rc! = 0" и "check_ruby.rc! = 0"?

when: check_python2.rc != 0 and check_ruby.rc != 0
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...