rrauenza
rrauenza

Reputation: 6983

How do you escape foo=bar in ansible?

I have a case where I need to pass an argument that has an equal sign in it:

- name: install virtualenv                                                          
        pip:                                                                              
            state: present                                                                
            name: mypackage                                                          
            virtualenv_python: /usr/bin/python3.6                                         
            virtualenv: "{{ perfdash_tools_venv_path }}"                                  
            extra_args: "--extra-index-url=https://myrepo"

Ansible thinks I'm trying to do k=v style:

ERROR! conflicting action statements: template, trigger

The error appears to be in 'tasks/main.yml': line 10, column 43, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

            extra_args: "--extra-index-url=https://myrepo"
                                          ^ here

There appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.

!unsafe doesn't seem to apply in this case.

(Yes, for now I can use whitespace, but that isn't always possible.)

Upvotes: 0

Views: 766

Answers (1)

F1ko
F1ko

Reputation: 4244

You can escape characters using {{ }} around it.

In your case {{'='}} will escape the equal sign.

Here is how your playbook should look like:

- name: install virtualenv                                                          
  pip:                                                                              
    state: present
    name: mypackage
    virtualenv_python: /usr/bin/python3.6
    virtualenv: "{{ perfdash_tools_venv_path }}"
    extra_args: "--extra-index-url{{'='}}https://myrepo"

Upvotes: 2

Related Questions