3.2.Ansible安装
在开始安装之前,为了避免firewalld和selinux的干扰,我们将其关闭。该操作仅限于实验环境,请勿在生产环境操作
关闭firewalld防火墙
$ systemctl stop firewalld $ systemctl disable firewalld
关闭selinux
# 编辑配置,将SELINUX设置为disable $ vi /etc/sysconfig/selinux SELINUX=disabled # 重启虚机,使配置生效 $ reboot # 重启成功后,执行如下命令,若返回Disabled则说明成功关闭SELINUX $ getenforce Disabled
Ansible的常见安装模式(CentOS7)
Yum包管理安装
# yum install epel-release
# yum repolist
# yum -y install ansible
python3+pip3+virtualenv安装
安装python3
$ yum install -y python3 $ which python3 /bin/python3
安装virtualenv
$ pip3 install virtualenv -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
创建python3虚拟空间并激活
$ python3 -m virtualenv ansible # Create a virtualenv if one does not already exist $ source ansible/bin/activate # Activate the virtual environment
安装ansible
$ python -m pip install ansible -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
验证ansible版本
$ ansible --version ansible 2.10.5 config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /opt/ansible/lib/python3.6/site-packages/ansible executable location = /opt/ansible/bin/ansible python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Python3.6+Ansible2.5源代码安装

预先安装Python3.6版本
安装virtualenv
# pip install virtualenv
创建Ansible账户并安装python3.6版本virtualenv实例
# useradd deploy && su - deploy # virtualenv -p /usr/local/bin/python3 .py3-a2.5-env
Git源代码安装ansible2.5
# cd /home/deploy/.py3-a2.5-env # git clone https://github.coy/ansible/ansible.git # cd ansible && git checkout stable-2.5
加载python3.6 virtualenv环境
# source /home/deploy/.py3-a2.5-env/bin/activate
安装ansible依赖包
# pip install paramiko PyYAML jinja2
在python3.6虚拟环境下加载ansible2.5
# source /home/deployl.py3-a2.5-env/ansible/hacking/env-setup -q
验证ansible2.5
# ansible --version
更多安装方式
更多安装方式请见:Installation Guide
Previous3.1.Ansible简介Next[3.3.Ansible playbooks入门和编写规范](编程学习/部署运维虚拟化/ansible/3.3.Ansible playbooks入门和编写规范.md)
Last updated
Was this helpful?