团队,我有以下任务在本地主机上运行。但是我需要在清单中定义的组下的所有主机上运行它,我需要为此执行委托_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