Trying to run a command in Azure VM via Ansible and Azure cli command but getting template issue
- name: Disable disk expansion
shell: | az vm run-command invoke -g {{ resource_group_name }} -n {{ instance_name }} --command-id RunShellScript --scripts "{{ 'sed -i \'/gp/s/\^/#/g\' /etc/config.cfg' }}"
Error
azure-arm.teracloud-azure-arm: msg: 'template error while templating string: unexpected char ''\'' at 142. String: az vm run-command invoke -g {{ resource_group_name }} -n {{ instance_name }} --command-id RunShellScript --scripts "{{ ''sed -i \''/gp/s/\^/#/g\'' /etc/config.cfg'' }}"'
I do not think you really want to have
{{}}for your--scriptspart as makes Jinja interpret this as variables to be replaced. Also The "escape madness" you applied to yoursedcommand is unnecessary and it should suffice to have it just like--scripts "sed -i '/gp/s/^/#/g' /etc/config.cfg":