I'm trying to used sed
to find and encrypt ansible_password
field in an inventory file and encrypt it with ansible-vault
command. But ansible-command
is failing throwing an sed
error, where as a simple echo is working fine.
sed -n "s/( *)(ansible_password: *)"(.*)"/$(echo 3)/p" sample.yml
is outputting the attribute value without the double quotes.
The ansible-vault
command:
sed -n "s/( *)(ansible_password: *)"(.*)"/$(ansible-vault encrypt_string --vault-password-file ~/password.txt --name 'ansible_password' '3')/p" sample.yml
is throwing an error message: sed: -e expression #1, char 67: unterminated ``s' command
Here's the line where the substitution is happening:
ansible_password: "somepassword"