Vasu
Vasu

Reputation: 187

File not created in ansible

I have installed ansible on one machine and trying to execute commands on another (remote) machinge.

  1. Ansible successfully installed
  2. Able to reach all hosts (local and remote). Tested with ansible all -m ping This was successful
  3. Trying to execute a simple command again ansible all -a 'echo "hello world" > ~/test' Executed successfuly. But the file test is not created.

Cannot find the reason why?

Upvotes: 1

Views: 746

Answers (1)

ProfHase85
ProfHase85

Reputation: 12173

Executing a command via ansible -a is equivalent to the command module, see command module. It is not processed via shell, therefore, >> (as well as other redirection operators) and $HOME are not available

In your case I would use

ansible -m 'shell' --args 'echo "hello world">>/home/ansibleremoteuser/test' all

In this case you would use the shell module which allows redirections.

Upvotes: 4

Related Questions