GithubHelp home page GithubHelp logo

avanov / ansible-galaxy-pyenv Goto Github PK

View Code? Open in Web Editor NEW
62.0 4.0 53.0 47 KB

Ansible Galaxy role for pyenv

Home Page: https://galaxy.ansible.com/avanov/pyenv/

License: MIT License

Shell 64.94% Jinja 35.06%
pyenv ansible-role

ansible-galaxy-pyenv's Introduction

avanov.pyenv

Build Status

Ansible Galaxy role for pyenv on Ubuntu / RedHat / OSX.

Install it with the following command:

$ ansible-galaxy install avanov.pyenv

Requirements

None

Role Variables

Here is the list of all variables and their default values:

  • pyenv_env: "user" (should be either "user" or "system")
  • pyenv_path: "{% if pyenv_env == 'user' %}{{ ansible_env.HOME }}/pyenv{% else %}/usr/local/pyenv{% endif %}"
  • pyenv_owner: "{{ ansible_env.USER }}"
  • pyenv_python_versions: ["3.4.1"]
  • pyenv_virtualenvs: [{ venv_name: "latest", py_version: "3.4.1" }]
  • pyenv_global: "3.4.1"
  • pyenv_update_git_install: no
  • pyenv_enable_autocompletion: no
  • pyenv_setting_path: "{% if pyenv_env == 'user' %}~/.bashrc{% else %}/etc/profile.d/pyenv.sh{% endif %}"

Dependencies

None

Example Playbook

- hosts: servers
  roles:
     - role: avanov.pyenv
       pyenv_path: "{{ home }}/pyenv"
       pyenv_owner: "{{ instance_owner }}"
       pyenv_global: "3.6.5"
       pyenv_update_git_install: no
       pyenv_enable_autocompletion: no
       pyenv_python_versions:
         - "3.6.5"
         - "3.4.1"
         - "2.7.8"
       pyenv_virtualenvs:
         - venv_name: "latest_v3"
           py_version: "3.4.1"

         - venv_name: "latest_v2"
           py_version: "2.7.8"

License

MIT

Author Information

Maxim Avanov (https://maximavanov.com/)

ansible-galaxy-pyenv's People

Contributors

adborden avatar alonisser avatar avolkov avatar bielstela avatar bossjones avatar edwinsmulders avatar fcce avatar hatappi avatar jakob1379 avatar jbouzekri avatar kinnarr avatar makkus avatar maxalbert avatar mzagozen avatar rouge8 avatar ryan5500 avatar t0k4rt avatar vincentchov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ansible-galaxy-pyenv's Issues

Adding a recent version of Python to an old pyenv install fails

TASK [avanov.pyenv : Install Python interpreters "['3.8.6']"] *************************************************************************************************************************************************************************
failed: [catalog-web1tf.internal.sandbox.datagov.us] (item=3.8.6) => {"ansible_loop_var": "item", "changed": true, "cmd": ". /home/pycsw/.pyenv/.pyenvrc && env PYTHON_CONFIGURE_OPTS=\"\" pyenv install 3.8.6", "delta": "0:00:00.183929", "end": "2020-11-03 18:24:12.543420", "item": "3.8.6", "msg": "non-zero return code", "rc": 2, "start": "2020-11-03 18:24:12.359491", "stderr": "python-build: definition not found: 3.8.6\n\nSee all available versions with `pyenv install --list'.\n\nIf the version you need is missing, try upgrading pyenv:\n\n  cd /home/pycsw/.pyenv/plugins/python-build/../.. && git pull && cd -", "stderr_lines": ["python-build: definition not found: 3.8.6", "", "See all available versions with `pyenv install --list'.", "", "If the version you need is missing, try upgrading pyenv:", "", "  cd /home/pycsw/.pyenv/plugins/python-build/../.. && git pull && cd -"], "stdout": "", "stdout_lines": []}

How to reproduce:

  1. Apply the role with pyenv_python_versions: ["3.8.5"]
  2. "pretend" that pyenv-build is on an old commit from before Python 3.8.6 was released:
cd /home/pycsw/.pyenv/plugins/python-build/../.. && git checkout d1ae4a1225f1c7e714316c4079416bbc6f4d60b0
  1. Apply the role with pyenv_python_versions: ["3.8.6"]

Valid values for pyenv_env are not obvious

Many thanks for providing this ansible-galaxy role @avanov! :)

Just a minor issue for usability: from the README it is not immediately clear what the valid values for the pyenv_env are. Looking at tasks/main.yml it, the suggested values seem to be "user" and "system".

As far as I can tell at a glance, it doesn't actually matter what the value is if it's different from "user", but from a user-friendliness perspective it would be nice if the "system" value was documented explicitly because it makes the meaning of the variable clearer.

Install .pyenvrc fails if owner != group

The 'Install .pyenvrc' task assumes that 'owner' and 'group' have the same name, specified by variable 'pyenv_owner'. If a group with the same name as the owner does not exist on the host, the install will fail with "chgrp failed: failed to look up group"

Add pyenv init step

It would be great if we could automate pyenv init step to actually activate pyenv.

way to set the git module's "accept_hostkey: yes"?

I'm getting this error:

TASK: [avanov.pyenv | Install PyEnv] ******************************************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> REMOTE_MODULE git repo=git://github.com/yyuu/pyenv.git dest=/home/orluke/.pyenv
<127.0.0.1> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ForwardAgent=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'Port=2223', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=root', '-o', 'ConnectTimeout=10', '127.0.0.1', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1410739017.84-66381583847007 && echo $HOME/.ansible/tmp/ansible-tmp-1410739017.84-66381583847007'"]
<127.0.0.1> PUT /var/folders/yl/chf4_71x5tq1fy9qs5tyj2nm0000gp/T/tmpU63VAJ TO /root/.ansible/tmp/ansible-tmp-1410739017.84-66381583847007/git
<127.0.0.1> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ForwardAgent=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'Port=2223', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=root', '-o', 'ConnectTimeout=10', '127.0.0.1', u"/bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1410739017.84-66381583847007/git; rm -rf /root/.ansible/tmp/ansible-tmp-1410739017.84-66381583847007/ >/dev/null 2>&1'"]
failed: [vagrant-debian] => {"failed": true}
msg: github.com has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module

FATAL: all hosts have already failed -- aborting

I can resolve the problem by manually running ssh [email protected] from the target host and then answering yes to this dialog:

vagrant@debian-7:~$ ssh [email protected]
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?

Updating pyenv_virtualenvs to new version does not update virtualenv

I had

      pyenv_virtualenvs:
       - venv_name: "latest_v3"
         py_version: "3.4.3"

at my playbook for a while. That worked perfectly during initial install. But later I had to update python version to 3.6.3.

      pyenv_virtualenvs:
       - venv_name: "latest_v3"
         py_version: "3.6.3"

As a result, new python version have been installed, but latest_v3 still points to version 3.4.3
So I had to do pyenv virtualenv --force 3.6.3 latest_v3 to update latest_v3 manually

pyenv: not found

running this:

  • hosts: 127.0.0.1
    connection: local
    sudo: yes
    roles:
    • role: avanov.pyenv
      pyenv_path: ~/.pyenv
      pyenv_owner: "MfM"
      pyenv_python_versions:
      • 3.4.3
      • 2.7.9
        pyenv_virtualenvs:
        • venv_name: nodeshot
          py_version: 2.7.9

I get error:

TASK: [avanov.pyenv | Create virtual environments] ****************************
failed: [127.0.0.1] => (item={'py_version': '2.7.9', 'venv_name': 'nodeshot'}) => {"changed": true, "cmd": ". ~/.pyenv/.pyenvrc && pyenv virtualenv 2.7.9 nodeshot", "delta": "0:00:00.001708", "end": "2015-07-01 21:40:46.430191", "item": {"py_version": "2.7.9", "venv_name": "nodeshot"}, "rc": 127, "start": "2015-07-01 21:40:46.428483", "warnings": []}
stderr: /bin/sh: 5: /home/MfM/.pyenv/.pyenvrc: pyenv: not found
/bin/sh: 1: pyenv: not found

FATAL: all hosts have already failed -- aborting

error: failed to download Python-3.6.5.tar.xz using role

When I use this role to install a version with

pyenv_python_versions:
  - "3.6.5"

I am getting the below error:

failed: [localhost] (item=3.6.5) => {
    "changed": true,
    "cmd": ". /opt/pyenv/.pyenvrc && pyenv install 3.6.5",
    "delta": "0:02:07.496284",
    "end": "2018-05-23 18:40:00.777833",
    "invocation": {
        "module_args": {
            "_raw_params": ". /opt/pyenv/.pyenvrc && pyenv install 3.6.5",
            "_uses_shell": true,
            "chdir": null,
            "creates": "/opt/pyenv/versions/3.6.5/bin/python",
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "item": "3.6.5",
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2018-05-23 18:37:53.281549",
    "stderr": "Downloading Python-3.6.5.tar.xz...\n-> https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz\nerror: failed to download Python-3.6.5.tar.xz\n\nBUILD FAILED (CentOS Linux 7 using python-build 1.2.4-2-gdad0fc7)",
    "stderr_lines": [
        "Downloading Python-3.6.5.tar.xz...",
        "-> https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz",
        "error: failed to download Python-3.6.5.tar.xz",
        "",
        "BUILD FAILED (CentOS Linux 7 using python-build 1.2.4-2-gdad0fc7)"
    ],
    "stdout": "",
    "stdout_lines": []
}

If I run . /opt/pyenv/.pyenvrc && pyenv install 3.6.5 as the pyenv_owner it works fine. I'm kind of at a loss of what's causing the issue.

Python is installed, but virtualenv is not

I want to use pyenv to install python, but then individual virtualenvs separately. However, I was surprised when virtualenv was not installed with python.

- name: install requested python version with pyenv
  include_role:
    name: avanov.pyenv
  vars:
    pyenv_path: "/home/app/.pyenv"
    pyenv_owner: "app"
    pyenv_global: "2.7.15"
    pyenv_python_versions: ["2.7.15"]
    pyenv_virtualenvs: []

- name: make sure virtualenv is ready
  pip: >-
    executable=/home/app/.pyenv/versions/2.7.15/bin/pip
    name=virtualenv
    state=present
    umask=0022
  become: true
  become_user: "app"

And I get this error:

    The full traceback is:
    WARNING: The below traceback may *not* be related to the actual failure.
      File "/tmp/ansible_pip_payload_WhiXU_/__main__.py", line 240, in <module>
        from pkg_resources import Requirement

    fatal: [python-app-trusty]: FAILED! => {
        "changed": false,
        "invocation": {
            "module_args": {
                "chdir": null,
                "editable": false,
                "executable": "/home/app/.pyenv/versions/2.7.15/bin/pip",
                "extra_args": null,
                "name": [
                    "virtualenv"
                ],
                "requirements": null,
                "state": "present",
                "umask": "0022",
                "use_mirrors": true,
                "version": null,
                "virtualenv": null,
                "virtualenv_command": "virtualenv",
                "virtualenv_python": null,
                "virtualenv_site_packages": false
            }
        },
        "msg": "No setuptools found in remote host, please install it first."
    }

    PLAY RECAP *********************************************************************
    python-app-trusty          : ok=13   changed=10   unreachable=0    failed=1

allow sudo: true specification

Currently tasks have a hard-coded 'sudo: false' clause. This over-rides any user specified 'sudo: true' in a playbook that calls on this role.

  1. Perhaps simply remove these and let the calling playbook decide on usage of sudo?
  2. Otherwise perhaps expose as a configurable flag? e.g {{ pyenv_as_sudo }} ?

Could be used for environments where a process manager (e.g supervisord) runs as root and would need to use a pyenv based python / virtualenv ..

Fails using default settings on Debian Stretch

Using just default settings, fails with this error building python 3.5.0:

failed: [default] (item=3.5.0) => {"changed": true, "cmd": ". /home/vagrant/pyenv/.pyenvrc && pyenv install 3.5.0", "delta": "0:01:31.295304", "end": "2019-01-24 10:07:56.192946", "item": "3.5.0", "msg": "non-zero return code", "rc": 1, "start": "2019-01-24 10:06:24.897642", "stderr": "Downloading Python-3.5.0.tar.xz...\n-> https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz\nInstalling Python-3.5.0...\nERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?\n\nPlease consult to the Wiki page to fix the problem.\nhttps://github.com/pyenv/pyenv/wiki/Common-build-problems\n\n\nBUILD FAILED (Debian 9.6 using python-build 1.2.9-2-g6309aaf2)\n\nInspect or clean up the working tree at /tmp/python-build.20190124100625.9522\nResults logged to /tmp/python-build.20190124100625.9522.log\n\nLast 10 log lines:\n(cd /home/vagrant/pyenv/versions/3.5.0/share/man/man1; ln -s python3.5.1 python3.1)\nif test \"xupgrade\" != \"xno\"  ; then \\\n\tcase upgrade in \\\n\t\tupgrade) ensurepip=\"--upgrade\" ;; \\\n\t\tinstall|*) ensurepip=\"\" ;; \\\n\tesac; \\\n\t ./python -E -m ensurepip \\\n\t\t$ensurepip --root=/ ; \\\nfi\nIgnoring ensurepip failure: pip 7.1.2 requires SSL/TLS", "stderr_lines": ["Downloading Python-3.5.0.tar.xz...", "-> https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz", "Installing Python-3.5.0...", "ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?", "", "Please consult to the Wiki page to fix the problem.", "https://github.com/pyenv/pyenv/wiki/Common-build-problems", "", "", "BUILD FAILED (Debian 9.6 using python-build 1.2.9-2-g6309aaf2)", "", "Inspect or clean up the working tree at /tmp/python-build.20190124100625.9522", "Results logged to /tmp/python-build.20190124100625.9522.log", "", "Last 10 log lines:", "(cd /home/vagrant/pyenv/versions/3.5.0/share/man/man1; ln -s python3.5.1 python3.1)", "if test \"xupgrade\" != \"xno\"  ; then \\", "\tcase upgrade in \\", "\t\tupgrade) ensurepip=\"--upgrade\" ;; \\", "\t\tinstall|*) ensurepip=\"\" ;; \\", "\tesac; \\", "\t ./python -E -m ensurepip \\", "\t\t$ensurepip --root=/ ; \\", "fi", "Ignoring ensurepip failure: pip 7.1.2 requires SSL/TLS"], "stdout": "", "stdout_lines": []}

Publish v1.1.0 to Ansible Galaxy

I noticed v1.1.0 was released, thank you! However, when I tried to install it, the version was unavailable in Ansible Galaxy. Would you mind publishing it?

As a work around, I added this to my requirements.yml:

- name: avanov.pyenv
  version: 1.1.0
  src: https://github.com/avanov/ansible-galaxy-pyenv.git

Missing required packages for Ubuntu/Debian

As you can see from here, there are 3 missing packages:

  • liblzma-dev
  • libncursesw5-dev
  • python3-openssl

I had some errors on a new Ubuntu version and it was solved by installing these missing packages.

No package `libselinux-python` available on RHEL8/CentOS8

I got a following error when using role on RHEL8/CentOS8:

TASK [avanov.pyenv : Install development packages necessary for building Python] *************************************************************************************************************************************************
task path: (...)/.ansible/roles/avanov.pyenv/tasks/RedHat.yml:5
fatal: [...]: FAILED! => {"changed": false, "failures": ["No package libselinux-python available."], "msg": "Failed to install some of the specified packages", "rc": 1, "results": []}

On RHEL8/Centos8 python3-libselinux should be installed instead of libselinux-python.
Ref.: kubernetes-sigs/kubespray#5046

pyenv_global seems to have no effect

Hello,

I may be missing something, but pyenv_global seems to have no effect for me when deploying to a Ubuntu Xenial machine.

Relevant playbook snippet:

  roles:
    - role: avanov.pyenv
      pyenv_owner: "{{ ubuntu_common_deploy_user_name }}"
      pyenv_path: "/home/{{ ubuntu_common_deploy_user_name }}/pyenv"
      pyenv_global: "3.7.2"
      pyenv_python_versions:
        - "3.7.2"

When I log in and run pyenv versions, this is the output:

[email protected]:~$ pyenv versions
* system (set by /home/deploy/pyenv/version)
  3.7.2

Installing undefined virtual envs

Why is it trying to install a virtual env i did not define??

the playbook:

---
- name: Install Pyenv for user gitlab-runner
  hosts: gitlab-22
  vars_files:
    - "{{ become_passwords }}"
  roles:
    - role: pyenv
      become: yes
      pyenv_global: "3.6.5"
      pyenv_path: "/home/jga/.pyenv"
      pyenv_owner: "jga"
      pyenv_update_git_install: no
      pyenv_enable_autocompletion: no
      pyenv_python_versions:
        - "3.8.5"

The error

TASK [pyenv : Create virtual environments] *************************************************************************************************************************************************
task path: /home/jga/Documents/it/deploy/roles/external/pyenv/tasks/install.yml:61
failed: [gitlab-22] (item={'venv_name': 'latest', 'py_version': '3.5.0'}) => {
    "ansible_loop_var": "item",
    "changed": true,
    "cmd": ". /home/jga/.pyenv/.pyenvrc && pyenv virtualenv 3.5.0 latest",
    "delta": "0:00:00.401261",
    "end": "2022-08-30 07:43:59.637853",
    "item": {
        "py_version": "3.5.0",
        "venv_name": "latest"
    },
    "rc": 1,
    "start": "2022-08-30 07:43:59.236592"
}

STDERR:

pyenv-virtualenv: `3.5.0' is not installed in pyenv.


MSG:

non-zero return code

root privileges

Hi,

I've just tested your playbook, works nicely, but for this I had to modify the tasks/main.yml to add sudo: yes in all tasks that need root privileges. If I did not do that and instead set sudo: yes as a var when calling your role

- { role: avanov.pyenv, sudo: yes }

then pyenv would be installed inside /root/.pyenv because the sudo: no variables get overridden in your pyenv installation tasks.

Could you please explain what your workflow is for using your role?

Thanks

PS: I'm new to this, and it might be the case that I did something wrong

Python 3.7.0 install fails on Ubuntu 16.04 due to missing dependency

The libffi-dev package is required for building Python 3.7.0.

Workaround is to override pyenv_debian_packages:

pyenv_debian_packages:
  # These packages are from the default value in the role
  - build-essential
  - git
  - curl
  - libssl-dev
  - libbz2-dev
  - libsqlite3-dev
  - libreadline-dev
  # This one is needed to build Python 3.7.0
  - libffi-dev

Compilation errors on Ubuntu 18.04 due to missing zlib dependency

When this role tries to compile a Python version on Ubuntu (tested it with 3.6.5 ans 2.7.15) it fails because an unmet compile dependency on zlib. After apt installing zlib1g-dev the problem went away, so you probably want to include this in the list of Debian dependencies

pyenv_virtualenvs and pyenv_python_versions should be undefined

Thanks for developing this role, I've used it a great deal, appreciate your efforts.

I'd like to suggest the following changes to the way the pyenv_virtualenvs are handled.

  1. Remove the pyenv_virtualenvs and pyenv_python_versions from defaults/main.yml
  2. Add the when: pyenv_virtualenvs is defined to the Create virtual environments task.
  3. Add the when: pyenv_python_versions is defined to the Create virtual environments task.

This way, if someone wants pyenv installed and no python versions or virtualenvs setup by default at the time this role is applied, then it handles that naturally. This allows the role to also be used to prepare an environment without requiring guesses to be made as to what the end use may need.

Create releases

Hello, I'd like to use this role. I find it much easier to manage third-party roles when they are versioned with semver. Would you consider doing that?

Pyenv Install not found

Fresh run of the role - when I try pyenv from a shell, it works fine.

failed: [localhost] (item=2.7.8) => {"changed": true, "cmd": ". ~/.pyenv/.pyenvrc && pyenv install 2.7.8", "delta": "0:00:00.372401", "end": "2018-08-04 22:09:00.083602", "failed": true, "item": "2.7.8", "msg": "non-zero return code", "rc": 1, "start": "2018-08-04 22:08:59.711201", "stderr": "pyenv: no such command `install'", "stderr_lines": ["pyenv: no such command `install'"], "stdout": "", "stdout_lines": []}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.