無服務、無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