ansible处理多台机器部署基础环境

本次以多台机器需部署zabbix客户端为例:

机器先做免密互信,ansible主机上执行ssh-keygen,一路回车,然后将公钥发送给需管理的主机:

ssh-copy-id root@IP

1、编辑hosts文件,添加需配置的主机IP,并测试连通性

[root@oxidized ansible]# vim /etc/ansible/hosts
[all]
10.10.80.110
10.10.80.111
10.10.80.112
10.10.80.114
10.10.80.115
10.10.80.116
[root@oxidized ansible]# ansible all -m ping
10.10.80.111 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
。。。
。。。
。。。

2、编写playbook剧本

[root@oxidized ansible]# cat zabbix.yml
- name: install zabbix
  hosts: all
  tasks:
    - name: copy zabbix-agent2_rpm
      copy:
        src: /root/zabbix-agent2-6.4.0-release1.el7.x86_64.rpm
        dest: /root/zabbix-agent2-6.4.0-release1.el7.x86_64.rpm
    - name: copy zabbix.sh
      copy:
        src: /etc/ansible/zabbix-install.sh
        dest: /root/zabbix-install.sh
    - name: install zabbix_agent2
      shell: sh /root/zabbix-install.sh
[root@oxidized ansible]# cat zabbix-install.sh
#!/bin/bash
cd /etc/yum.repos.d/ && mkdir bak
mv *.repo bak/
cat >>/etc/yum.repos.d/local.repo <

3、执行playbook

[root@oxidized ansible]# ansible-playbook zabbix.yml
查看执行结果0fails即成功。

你可能感兴趣的:(系统运维,ansible,服务器,linux)