Ansible issue while running sed command

23 Views Asked by At

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'' }}"'

1

There are 1 best solutions below

0
Marcin Orlowski On

I do not think you really want to have {{ }} for your --scripts part as makes Jinja interpret this as variables to be replaced. Also The "escape madness" you applied to your sed command is unnecessary and it should suffice to have it just like --scripts "sed -i '/gp/s/^/#/g' /etc/config.cfg":

- 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"