- name: Go to the folder command: chdir=/opt/tools/temp
When I run my playbook, I get:
TASK: [Go to the folder] ***************************** failed: [host] => {"failed": true, "rc": 256} msg: no command given
Any help is much appreciated.
You can change into a directory before running a command with ansible with chdir .
You can change and specify the directory path where you want to run the command using the chdir parameter. This parameter is available for both command and shell module. You can also change the default shell by specifying the absolute path of the require shell in the executable parameter.
In an Ansible playbook, when local_action is used, Ansible will run the module work mentioned under it on the controller node. Mostly modules used with local_action are shell and command. As you can do almost all the tasks using these modules on the controller node.
To run an Ansible task as a specific user, rather than the normal root user, you can use the become_user directive and pass the user's username to execute the task. This is quite like using the sudo -u command in Unix.
There's no concept of current directory in Ansible. You can specify current directory for specific task, like you did in your playbook. The only missing part was the actual command to execute. Try this:
- name: Go to the folder and execute command command: chdir=/opt/tools/temp ls
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With