0

i need to clear the contents of a file on remote hosts using shell module in ansible but unable to do so

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

Error:

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
  • Maybe you wanted a colon in front? (The 'true' operator) Commented Jun 3, 2017 at 6:51

2 Answers 2

0

@Jeff Schaller this helped to solve the issue,,

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

Now what if i have multiple commands to run

0

You can use it as below for multiple commands:

    - name: Copy var directory
      shell: |
        cmd1
        cmd2
        cmd3
      args:
        executable: /bin/bash
1
  • @Mohammed Ali if this works Can you please accept the answer Commented Apr 17, 2020 at 14:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.