Reputation: 169
I´m using ansible -a command to execute on my inventory some tastsk (df -h, check folders...). But now, I need to create a user on all the hosts.
I´m using the following command:
ansible -i [INVENTORYNAME].inventory allservers -m shell -a "sudo useradd -c "Name & lastname" [USERNAME]" >> [FILE].txt --extra-vars "ansible_sudo_pass=[MYPASS]" -b
But it doesn´t work. How can I include special characters in my commands?
Thank you.
Upvotes: 0
Views: 4726
Reputation: 66
Your current command has nested double quotes.
You can either use single quotes outside:
ansible -i inventory all -m shell -a 'sudo useradd -c "Name & lastname" [USERNAME]' >> [FILE].txt --extra-vars "ansible_sudo_pass=[MYPASS]" -b
or escape the double quotes inside:
ansible -i inventory all -m shell -a "sudo useradd -c \"Name & lastname\" [USERNAME]" >> [FILE].txt --extra-vars "ansible_sudo_pass=[MYPASS]" -b
The second options will allow you to include environment variables from the machine executing the Ansible command (your PC).
As a side note, I highly recommend using the user module.
sudo
is also redundant if you use -b
Upvotes: 3