patternMinor
passing args to shell module in Ansible adhoc command
Viewed 0 times
passingmoduleshellargsadhocansiblecommand
Problem
Is it possible to pass
I can pass the
For example, what is the adhoc equivalent to this task?
args, to the shell module when running it as an adhoc command?I can pass the
free_form parameter using -a, but I am trying to figure out how to specify additional arguments, such as chdir or executable.For example, what is the adhoc equivalent to this task?
- name: Change working dir to somedir/ and run somescript.sh using bash
shell: somescript.sh >> somelog.txt
args:
chdir: somedir/
executable: /bin/bashSolution
Append the parameters after the command. See the example below.
# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | CHANGED | rc=0 >>
/scratch/tmp
test
# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | SUCCESS | rc=0 >>
skipped, since /scratch/tmp/test existsCode Snippets
# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | CHANGED | rc=0 >>
/scratch/tmp
test
# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | SUCCESS | rc=0 >>
skipped, since /scratch/tmp/test existsContext
StackExchange DevOps Q#7958, answer score: 8
Revisions (0)
No revisions yet.