Install Python from pyenv and use the pip module using Ansible

Asked 2 years ago, Updated 2 years ago, 67 views

Call the Ansible script from Vagrant and
I would like to build Python using pyenv and eventually implement a script to install Django.
Using the script below,

-name —Install the specified version of Python
  shell:bash-lc "pyenv install {{python_version}}}"
  become —false

- name —Reflects the specified version in the working directory
  shell:bash-lc "pyenv local {{python_version}}}"
  args:
    chdir: "{work_dir}}"
  become —false

- name —Pip upgrade
  shell:bash-lc "pip install --upgrade pip"
  args:
    chdir: "{work_dir}}"
  become —false

- name —install django
  pip:
    name —django
    chdir: "{work_dir}}"
    version: "{{django_version}}"
    executable:pipe
  become —false

I received the following error.You said you don't have a pip module, but
When I logged in to the guest OS with vagrantssh, the pip command was found successfully.
Is it possible to build python from pyenv and call the pip under its influence from Ansible?
I would appreciate it if you could let me know.

TASK [django:install django] ****************************************************
fatal: [127.0.0.1]: FAILED!=> { "changed": false, "failed": true, "msg": "Unable to find any of pip to use.pipe needs to be installed."}
    to retry, use: --limit@/vagrant/playbooks/main.retry

python vagrant ansible

2022-09-30 19:17

1 Answers

I solved myself.
Ansible uses the default Python (/usr/bin/python), so
You will need to modify the Python interpreter using the following modules:

set_fact:ansable_python_interpreter=/home/{{work_user}}/.pyenv/shims/python


2022-09-30 19:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.