Run shell command from Ansible
8,333
Why don't you use the chdir
parameter?
chdir
: cd into this directory before running the command
From the documentation:
- name: Change the working directory to somedir/ before executing the command.
command: somescript.sh
args:
chdir: somedir/
Related videos on Youtube
Author by
shashank barki
Updated on September 18, 2022Comments
-
shashank barki over 1 year
I have a shell script which just changes directory (here directory path is given).
shell file
#!/bin/bash p="dir/file/create" cd "$p" exec bash
Ansible playbook
--- - hosts: localhost gather_facts: true become: true become_user: oracle become_flags: 'content-ansible' tasks: - name: changing dir now.. command: sh /dir/file/create/vars.sh
I want to run a shell script to change directory path in ANSIBLE and run subsequent shell file(#2) in the directory (again shell script).
Ansible playbook completes but I never am able to get into a directory and execute the shell script(#2).
-
kaliko about 5 yearsThe
chdir
parameter is also available for the shell module.