
원격 호스트에서 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 --limit
오류! 충돌하는 작업 명령문: 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 }}'