N
N
Nikolay Baranenko2021-12-09 21:53:47
Python
Nikolay Baranenko, 2021-12-09 21:53:47

How to correctly pass the value of a variable to ansible_python_interpreter?

I have a playbook.yml that deploys containers to a test environment.
For Tasks that do
Docker Pull and Docker Container restart
I want to override ansible_python_interpreter with ansible_python3_interpreter
which comes after Task
Create Python ENV and install requerements - docker

---
- name: Deploy Web on Host
  hosts: '{{ target_host }}'
  vars:
    python_virtualenv: /opt/python_envs/py36
    ansible_python3_interpreter: "/opt/python_envs/py36/bin/python"     
    ansible_python2_interpreter: "/usr/bin/python2.7"
    CI_REGISTRY: "{{ lookup('env','CI_REGISTRY') }}"

    - name: Create Python ENV and install requirements - docker
      pip:
        name: [ "docker", "docker-compose"]        
        # extra_args: "--user"
        virtualenv: '{{ python_virtualenv }}'
        virtualenv_command: /usr/bin/python3.6 -m venv
        # virtualenv_site_packages: yes

    - name: Pull Docker image api
      docker_image:
        name: "{{CI_REGISTRY}}/mvp1/tools/web:{{ api_version }}"
        source: pull
      vars:
        ansible_python_interpreter: "{{ ansible_python3_interpreter }}"


an error is returned
fatal: [project-test]: UNREACHABLE! => {
    "changed": false,
    "unreachable": true
}
MSG:
EOF on stream; last 100 lines received:
bash: {{: command not found


how to correctly pass the value of a variable to ansible_python_interpreter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2021-12-10
@opium

so you have a bash error, why do you run yaml in bash?
you also have a lot of variables in single quotes, some in double quotes, some without,
do everything uniformly at first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question