centos7如何安装ansible
时间: 2023-09-11 18:04:35 浏览: 109
1. 首先要确保已经安装了Python和Python-pip。
2. 执行以下命令安装ansible:
```
sudo yum install epel-release
sudo yum install ansible
```
3. 确认ansible已经安装成功,执行以下命令:
```
ansible --version
```
输出结果类似于:
```
ansible 2.9.21
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
```
4. 安装完成后,可以通过编写ansible playbook来管理主机。例如:
```
- hosts: all
tasks:
- name: Install Apache
yum:
name: httpd
state: latest
- name: Start Apache service
service:
name: httpd
state: started
```
保存为一个名为`apache.yml`的文件,然后通过以下命令来运行:
```
ansible-playbook apache.yml
```
这将在所有主机上安装和启动Apache服务。
阅读全文