【Python】Ansible安装与使用,pythonansible安装


机器信息

主机:192.168.88.101(centos7)
从机:192.168.88.104(centos7)
从机:192.168.88.105(centos7)

安装

yum install -y epel-release
yum install -y ansible

设置SSH免密码登陆

1)在主机中执行:
ssh-keygen

2)使用ssh-copy-id命令来复制Ansible公钥到从机中:
ssh-copy-id -i root@192.168.88.104
ssh-copy-id -i root@192.168.88.105

修改Ansible配置文件

1)vi /etc/ansible/hosts
2)增加需要管理的从机组:
...
[my-servers]
192.168.88.104
192.168.88.105
...

在主机中执行命令测试

ansible -m ping 'my-servers'

Playbook(安装nginx)

1)创建 nginx_install.yml,并写入:

- hosts: my-servers
  remote_user: root
  tasks:
  - name: install nginx
    yum: pkg=nginx state=latest
  - name: start nginx
    service: name=nginx state=started

2)执行Playbook:

ansible-playbook nginx_install.yml

相关内容

    暂无相关文章