ansible安装配合Virtualenv
Posted wengshaohang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible安装配合Virtualenv相关的知识,希望对你有一定的参考价值。
ansible安装
-
让项目运行在一个独立的局部的 Python 环境中,使采用不同环境的项目互不干扰。
安装方式:
yum安装:
安装EPEL源
yum install epel-release yum install ansible
编译安装:
yum-y install python-jinja2 PyYAML python-paramiko python-babel python-crypto tar xf ansible-1.5.4.tar.gz cd ansible-1.5.4 python setup.py build python setup.py install mkdir/etc/ansible cp-r examples/*/etc/ansiblel
Git方式:(我是用的这种)
使用python自带的python virtualenv工具隔离Python3.6、Ansible和系统其他python环境。
编译安装python3.6.5
[root@localhost ~]# wget http://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
[root@localhost ~]# tar xf Python-3.6.5.tar.xz
[root@localhost ~]# cd Python-3.6.5
安装编译所需的依赖
[root@localhost Python-3.6.5]# yum install -y gcc zlib* openssl*
开始编译
[root@localhost Python-3.6.5]# ./configure --prefix=/usr/local/ --with-ensurepip=install --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
--prefix=/usr/local/ ---指定安装路径 --with-ensurepip=install ----安装pip --enable-shared ---disable/enable building shared python library 启用共享函数构建的库 LDFLAGS="-Wl,-rpath /usr/local/lib" ----Wl 将后面跟的参数传递给连接器 ld;-rpath 添加运行时库的搜索路径 现代linux的发行版配置的python都是编译成share library方式,有些第三方软件如mod_wsgi和Blender必须要这样才能正常运行。但是,如果把python编译成share library,就必须告知如何才能找到这个library。有两种办法达到这个目的: 通过在configure命令的最后加入LDFLAGS="-Wl,-rpath /usr/local/lib"选项把路径编译到可执行文件里面去
接下来安装
[root@localhost Python-3.6.5]# make && make altinstall,输入echo $?查看命令是否执行成功
安装virtualenv
[root@localhost Python-3.6.5]# cd /usr/local/bin/
[root@localhost bin]# ln -s /usr/local/bin/pip3.6 /usr/local/bin/pip
[root@localhost bin]# pip install virtualenv ,速度有点慢安装过程中,如果出现如下 error 信息是,可以尝试切换源重新下载
切换清华源 pip install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple/
安装成功后,创建ansible账户
[root@localhost ~]# useradd deploy
切换到deploy用户
[root@localhost ~]# su - adeploy
安装python3.6virtualenv实例
[deploy@localhost ~]$ virtualenv -p /usr/local/bin/python3.6 .py3-a2.10-env
Already using interpreter /usr/local/bin/python3.6 Using base prefix ‘/usr/local‘ New python executable in /home/deploy/.py3-a2.5-env/bin/python3.6 Also creating executable in /home/deploy/.py3-a2.5-env/bin/python Installing setuptools, pip, wheel... done.
Git源码安装ansible最新版
使用root账户安装nss curl
[root@localhost ~]# yum install nss curl -y
然后切到deploy用户,进入之前创建的.py3-a2.5-env目录下,克隆ansible源码
[root@localhost ~]# su - deploy
[deploy@localhost ~]$ cd /home/deploy/.py3-a2.5-env/
[deploy@jenkins .py3-a2.5-env]$ git clone https://github.com/ansible/ansible.git
克隆慢解决方法
去这个网站注册账号https://gitee.com/,点击导入,等几分钟就下载好了
然后复制地址下载即可[deploy@jenkins .py3-a2.5-env]$ git clone https://gitee.com/wengsh/ansible.git
下载完成后,加载python3.6 virtualenv环境
[deploy@jenkins .py3-a2.5-env]$ source /home/deploy/.py3-a2.5-env/bin/activate
(.py3-a2.5-env) [deploy@jenkins .py3-a2.5-env]$
接下来安装ansible依赖包
(.py3-a2.5-env) [deploy@jenkins .py3-a2.5-env]$ pip install paramiko PyYAML jinja2
在python3.6虚拟环境下加载ansible2.5
(.py3-a2.5-env) [deploy@jenkins ansible]$ source /home/deploy/.py3-a2.5-env/ansible/hacking/env-setup -q
查看ansible版本
(.py3-a2.5-env) [deploy@jenkins ansible]$ ansible --version
ansible 2.10.0.dev0
config file = None
configured module search path = [‘/home/deploy/.ansible/plugins/modules‘, ‘/usr/share/ansible/plugins/modules‘]
ansible python module location = /home/deploy/.py3-a2.5-env/ansible/lib/ansible
executable location = /home/deploy/.py3-a2.5-env/ansible/bin/ansible
python version = 3.6.5 (default, Jan 31 2020, 17:16:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
到此,ansible安装完成
以上是关于ansible安装配合Virtualenv的主要内容,如果未能解决你的问题,请参考以下文章
GitLab介绍GitLab的工作流程Gitlab安装配置环境Ansible配合virtualenv安装配置
GitLab介绍GitLab的工作流程Gitlab安装配置环境Ansible配合virtualenv安装配置
Ansible virtualenv下pip3安装requirements报错