无服务、无agent、采用ssh管理远程主机、多线程
一、配置文件/etc/ansible/ansible.cfg
二、管理方式
(1)ad-hoc 临时命令
(2)playbook剧本php
远程管理
1、新建一个目录
[root@room8pc16 nsd1709]# mkdir ansi
[root@room8pc16 nsd1709]# cd ansi
二、建立配置文件
[root@room8pc16 ansi]# vim ansible.cfg
[defaults]
inventory = inventory # 定义被管理主机到哪一个文件中查找
remote_user = root # ssh到远程主机的用户
三、建立主机清单
[root@room8pc16 ansi]# vim inventory
[dbservers] # 定义主机组名
192.168.4.1 # 定义组成员主机mysql
[webservers]
192.168.4.2
192.168.4.3
四、列出主机命令,虽然all没有定义,可是它是保留字,表示全部主机
[root@room8pc16 ansi]# ansible all --list-hosts
[root@room8pc16 ansi]# ansible dbservers --list-hosts
[root@room8pc16 ansi]# ansible webservers --list-hosts
五、测试到远程主机的通讯
[root@room8pc16 ansi]# ansible all -m ping -k
六、在全部的主机上执行任意命令
[root@room8pc16 ansi]# ansible all -a 'touch /opt/abc.txt' -klinux
如下命令是远程开机命令,与ansible无关
[root@room8pc16 ansi]# ether-wake -i enp2s0 xx:xx:xx:xx:xx:xxweb
name: configure vsftpd
hosts: all
tasks:sql
name: install vsftpd
yum:
name: vsftpd
state: latestshell