I couldn't seem to find an answer to this query here already and can't seem to find anything with googling.
I am trying to run an adhoc command on a remote box using ansible and I keep getting "a duplicate paramter was found in the argument string" failure, this happens when I use the raw module but not the shell module.
The exact error message is the following:
hostname1 | FAILED => a duplicate parameter was found in the argument string (variable)
hostname2 | FAILED => a duplicate parameter was found in the argument string (variable)
By example here is a command that doesn't work, it seems to object to setting the same variable twice, despite the fact this is valid bash:
ansible group -i hosts-file -m raw -k -s -a "variable=1 ; echo \$variable; variable=2; echo \$variable"
The reason I ask is because I am trying to run a command with a case statement to set a variable on remote boxes which do not have python installed and I am not allowed to configure them in any way.
By example:
ansible group -i hosts-file -m raw -k -s -a "
for file in \$(find . -name \"test*\")
do
case \$file in
test1) variable=test1 ;;
test2) variable=test2 ;;
test3) variable=test3 ;;
esac
echo \$variable
done
"
The syntax here may not be spot on but hopefully you get the idea, it can't cope with setting the same variable multiple times. I know that in the above code I could get around the problem by putting the echo into the case statement but my code in reality is a lot more complicated than an echo so I end up with many more lines of code by duplicating the action into the case statement.
Does anyone know how to fix this? Any help is greatly appreciated, thanks.
EDIT: I am on ansible version 1.7, as per answer below, this issue does not affect anything beyond 2.0.
This is a bug. Ansible is parsing the input string for args for some stupid reason. Try this as a work around:
ansible hosts -i hosts -m raw -a '/bin/bash -c "variable=1; echo \$variable; variable=2; echo \$variable;"' -vvv
This bug is also only present in <=1.9. 2.0 works.