
我想在遠端主機上運行 a.sh 並獲取所有輸出檔案。帶有時間戳記的輸出檔。您可以在下面看到我的 ansible 任務。
---
- name: 'abcd'
hosts: 'all'
gather_facts: 'false'
tasks:
- name : 'Copy the script to /tmp/ and set permission'
copy :
src : 'a.sh'
dest: '/tmp'
mode: '0700'
- name: 'Execute the script'
shell: >
/tmp/a.sh
register: 'results'
- name: 'Display output'
debug:
msg: '{{ results.stdout }}'
- name: 'Remove script'
file:
path: '/tmp/a.sh'
state: 'absent'
- name: 'fetch'
shell: "ls /tmp/test_Prereq_*"
register: path_files
fetch :
src : '/tmp/"{{item}}"'
dest : '/home/vj/testout'
with_items: '{{ path_files.stdout }}'
ansible-playbook report_task.yml --限制
錯誤!衝突的操作語句:shell、fetch
該錯誤似乎位於“/home/vicheruk/report_task.yml”:第 24 行第 8 列中,但可能位於文件中的其他位置,具體取決於確切的語法問題。
有問題的行似乎是:
state: 'absent'
- name: 'fetch'
^ here
有任何想法嗎?
答案1
你的劇本在文法上是錯的。fetch
是一個模組,需要在自己的任務中呼叫。
在同一個文件中循環和寫入也沒有太多意義。也許您也想包含{{ item }}
在參數中。dest
這應該可以解決問題:
- name: 'register files'
shell: "ls /tmp/test_Prereq_*"
register: path_files
- name: fetch
fetch:
src: '/tmp/"{{ item }}"'
dest: '/home/vj/testout-{{ item }}'
with_items: '{{ path_files.stdout }}'