Доступный вложенный цикл для запуска контрольной суммы на всех хостах в группе инвентаризации - PullRequest
0 голосов
/ 06 ноября 2019

Команда, у меня ниже задача, которая работает на локальном хосте. Но мне нужно запустить его на всех хостах в группе, определенной в инвентаре, для которой мне нужно сделать Delegate_to и with_items. Любой совет, как можно выполнить эту задачу на всех хостах?

      - name: verify if kernel modules exists
        stat:
          path: /lib/modules/{{ kernel_version }}/kernel/{{ item.dir }}/{{ item.module_name }}
          checksum_algorithm: sha1
        register: res
        failed_when: res.stat.checksum != item.sha1
        with_items:
          - { dir: fs/fscache, module_name: fscache.ko, sha1: "{{ checksum.fscache }}"  }
          - { dir: fs/cachefiles, module_name: cachefiles.ko, sha1: "{{ checksum.cachefiles }}" }
          - { dir: fs/isofs, module_name: isofs.ko, sha1: "{{ checksum.isofs }}" }
          - { dir: drivers/target , module_name: target_core_user.ko, sha1: "{{ checksum.target_core_user }}" }
          - { dir: drivers/target/loopback , module_name: tcm_loop.ko, sha1: "{{ checksum.tcm_loop }}" }

     - fail:
          msg: "FAILED TO FIND {{ item.item }}"
        with_items: "{{ res.results }}"
        when: item.stat.exists == False

Нужно ли использовать ниже?

        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-gpu-node'] }}”

пытался использовать хосты: непосредственно в задаче, как показано ниже, но я получаю синтаксисошибка

# tasks file for maglev-deployment
      - name: "verify if kernel modules exists"
        hosts: kube-gpu-node
        stat:
          path: /lib/modules/{{ gpu_node_kernel }}/kernel/{{ item.dir }}/{{ item.module_name }}
          checksum_algorithm: sha1
        register: res
        #failed_when: res.results.item.sha1 != item.sha1
        #failed_when: res.results[0] == ''
        with_items:
          - { dir: fs/fscache, module_name: fscache.ko, sha1: "{{ checksum.fscache }}"  }
          - { dir: fs/cachefiles, module_name: cachefiles.ko, sha1: "{{ checksum.cachefiles }}" }
          - { dir: fs/isofs, module_name: isofs.ko, sha1: "{{ checksum.isofs }}" }
          - { dir: drivers/target , module_name: target_core_user.ko, sha1: "{{ checksum.target_core_user }}" }
          - { dir: drivers/target/loopback , module_name: tcm_loop.ko, sha1: "{{ checksum.tcm_loop }}" }
        ignore_errors: yes
      - debug:
          var: res

      - name: check if cachefilesd.conf  exists
        stat:
          path: /etc/cachefilesd.conf
        register: result

ERROR! 'hosts' is not a valid attribute for a Task

The error appears to be in '/home/ssh/tasks/main.yaml': line 2, column 9, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
deployment
      - name: "verify if kernel modules exists"
        ^ here

This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...