Ansible安装实录
程序员文章站
2022-06-05 18:42:42
...
1. 安装python
下载python安装包
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar xf Python-3.6.5.tar.xz
进入到Python文件目录
cd Python-3.6.5
创建安装make文件
./configure --prefix=/opt/software/python3.6.5 --enable-optimizations
创建
make && make install
创建python3的软连接
ln -s /opt/software/python3.6.5/bin/python3.6 /usr/bin/python3
创建pip软连接
ln -s /opt/software/python3.6.5/bin/pip3.6 /usr/bin/pip3
看看pip要不要升级
python3 -m pip install --upgrade pip
安装下virtualenv
python3 -m pip install virtualenv
网络不是很好的话,建议先从这里下载
https://files.pythonhosted.org/packages/05/f1/2e07e8ca50e047b9cc9ad56cf4291f4e041fa73207d000a095fe478abf84/virtualenv-16.7.9-py2.py3-none-any.whl
创建虚拟环境
创建用户
groupadd ansible
useradd -s /bin/bash -d /sunline/ansible -g ansible ansible
passwd ansible
切换用户
su ansible
创建env环境
python3 -m virtualenv -p /opt/software/python3.6.5/bin/python3.6 .py3-ansible-env
进入虚拟环境
source /sunline/ansible/.py3-ansible-env/bin/activate
安装基础依赖
pip install pycrypto paramiko PyYAML jinja2
拷贝文件
cp -r ~/ansible-stable-2.5 ./ansible
安装ansible
python3.6 ansible/setup.py install
验证
查看下版本
ansible --version
ansible-playbook --version
创建一个playbooks的基本组织结构
(.py3-ansible-env) [[email protected] playbook_test]$ tree .
.
├── deploy.yml
├── inventory
│ └── test_env
├── roles
└── testbox
└── tasks
└── main.yml
4 directories, 3 files
(.py3-ansible-env) [[email protected] playbook_test]$
免密登录
一个免密登录
ssh-******
ssh-copy-id [email protected]
enter root password
执行第一个测试
(.py3-ansible-env) [[email protected] playbook_test]$ ansible-playbook -i inventory/test_env ./deploy.yml
执行结果
PLAY [testservers] *******************************************************
TASK [Gathering Facts]
ok: [test.example.com]
TASK [testbox : Print Test Snow] ******************************************
changed: [test.example.com]
PLAY RECAP ***************************************************************************
test.example.com : ok=2 changed=1 unreachable=0 failed=0
好了完成了 !
参考文献
https://blog.51cto.com/increase/2091140
http://www.showerlee.com/archives/1862
https://blog.csdn.net/sinat_39403631/article/details/83473272
下一篇: virtualenv 虚拟环境的设置