ansible playbook 安装python版本管理神器-pyenv

ansible playbook 安装python版本管理神器-pyenv 

环境:

腾讯云 Centos7.4 64位

基础安装

确认安装gcc, openssl openssl-devel升级到最新版本, yum -y install gcc openssl openssl-devel

ansible-playbook 脚本

[root@VM_32_7_centos playbook]# cat pyenv_python3.yml

---
- hosts: '{{ host }}'
  remote_user: root
  gather_facts: true
  tasks:
  - name: Install pyenv 
    git: 
      repo: https://github.com/pyenv/pyenv.git
      dest: "/root/.pyenv" 

  - name: Install pyenv-virtualenv plugin 
    git: 
      repo: https://github.com/pyenv/pyenv-virtualenv.git
      dest: "/root/.pyenv/plugins/pyenv-virtualenv" 

  - name: Add path etc to .bashrc. 
    lineinfile: 
      dest: "/root/.bashrc" 
      state: present 
      create: yes 
      line: "{{ item }}" 
    with_items: 
      - 'export PYENV_ROOT="$HOME/.pyenv"' 
      - 'export PATH="$PYENV_ROOT/bin:$PATH"' 
      - 'eval "$(pyenv init -)"' 
      - 'eval "$(pyenv virtualenv-init -)"' 
  - name: Ensure .pyenv permissions are set properly 
    file: path=/root/.pyenv 
     recurse=yes 
     owner=root
     group=root
     state=directory 

  - name: Install default python version 
    shell: . /root/.bashrc && pyenv install 3.5.1 
    tags:
     - python3
  - name:
    shell:  . /root/.bashrc && pyenv global 3.5.1
  - name:
    shell:  pip install --upgrade pip
    tags: pip

执行playbook

ansible-playbook pyenv_python3.yml  --extra-vars "host=172.21.32.8" 

验证

[root@VM_32_8_centos bin]# python3 --version 
Python 3.5.1
[root@VM_32_8_centos bin]# pip3 --version
pip 18.1 from /root/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pip (python 3.5)

pyenv 用法

[root@centos-32-7 playbook]# pyenv --help
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

版本切换

显示可选安装列表:

pyenv install -l

安装另一版本:

pyenv install 3.6.6

显示当前系统内可选择的版本:可以看到现在有两个版本,当前版本是3.6.6

[root@centos-140 ~]# pyenv versions
system
3.5.1
* 3.6.6 (set by /root/.pyenv/version)

查看当前版本:

[root@centos-140 ~]# pyenv version
3.6.6 (set by /root/.pyenv/version)

切换默认版本:

pyenv global 3.5.1

再次查看当前版本:

[root@centos-140 ~]# pyenv version
3.5.1 (set by /root/.pyenv/version)

转载于:https://my.oschina.net/winniepoohmeng/blog/2992419

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值