Ansible 쉘 모듈 문제

Ansible 쉘 모듈 문제

Ansible의 쉘 모듈을 사용하여 원격 호스트의 파일 내용을 지워야 하는데 그렇게 할 수 없습니다.

---
 - hosts: ansi1
   become: yes
   gather_facts: no
   tasks:
   - name: checking shell power
     shell:
        >/tmp/1.txt
     args:
      executable: /bin/bash

실수:

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/etc/ansible/shell.yml': line 8, column 10, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

     shell:
        >/tmp/1.txt
         ^ here

답변1

@Jeff Schaller는 문제를 해결하는 데 도움이 됩니다.

---
 - hosts: ansi2
   become: yes
   gather_facts: no
   tasks:
   - name: checking shell power
     shell:
             '>/tmp/1.txt'
     args:
      executable: /bin/bash

이제 실행할 명령이 여러 개 있으면 어떻게 될까요?

답변2

다음과 같은 여러 명령과 함께 사용할 수 있습니다.

    - name: Copy var directory
      shell: |
        cmd1
        cmd2
        cmd3
      args:
        executable: /bin/bash

관련 정보