[英]not able to execute block module in ansible yml script
我在 ansible 劇本下方使用塊模塊。 基本上,如果files
存在,那么我只想執行 Play 2 和 Play3,但由於某種原因,當我在 playbook 下面執行時出現錯誤。
---
- name: Play 1
hosts: 127.0.0.1
tasks:
- name: find the latest file
find: paths=/var/lib/jenkins/jobs/process/workspace/files
file_type=file
age=-1m
age_stamp=mtime
register: files
- name: Play 2 & 3 if Play 1 has a file
block:
- name: Play 2
hosts: all
serial: 5
tasks:
- name: copy latest file
copy: src=data_init/goldy.init.qa dest=/data01/admin/files/goldy.init.qa
- name: copy latest file
copy: src=data_init/goldy.init.qa dest=/data02/admin/files/goldy.init.qa
- name: Play 3
hosts: 127.0.0.1
tasks:
- name: execute command
shell: ./data_init --init_file ./goldy.init.qa
when: files != ""
下面是錯誤。 知道我在這里做錯了什么嗎?
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/var/lib/jenkins/jobs/process/workspace/test.yml': line 14, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
block:
- name: Play 2
^ here
這有幾處錯誤,我假設您是 ansible 的新手。 您不能將名稱放在塊上。 你的結構也是錯誤的。 文件未定義。 嘗試:
---
- name: Play 1
hosts: 127.0.0.1
tasks:
- name: find the latest file
find: paths=/var/lib/jenkins/jobs/process/workspace/files
file_type=file
age=-1m
age_stamp=mtime
register: files
- debug:
msg: "{{ files }}"
when: files != ""
- block:
- name: copy latest file
copy: src=data_init/goldy.init.qa dest=/data01/admin/files/goldy.init.qa
- name: copy latest file
copy: src=data_init/goldy.init.qa dest=/data02/admin/files/goldy.init.qa
- name: execute command
shell: ./data_init --init_file ./goldy.init.qa
when: files != ""
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.