puppet
ansible
slatstack
epel源
第一步: 下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo第二步: 安装ansible
yum install -y ansiblesalt 控制节点需要安装salt-master
salt 被控节点需要安装salt-minion
ansible 通过ssh来连接并控制被控节点
ssh 的认证方式
密码连接
秘钥连接
ssh 秘钥登录
ssh-keygen # 用来生成ssh的密钥对一路回车ssh-copy-id 192.168.107.131 # 复制秘钥到远程主机连接你需要控制的机器查看ansible生成的文件
rpm -ql ansible|more /etc/ansible/etc/ansible/ansible.cfg/etc/ansible/hosts/etc/ansible/roles编辑ansible的hosts文件 vi /etc/ansible//hosts #在这里面加入你要控制的机器ip # This is the default ansible 'hosts' file.## It should live in /etc/ansible/hosts## - Comments begin with the '#' character # 用#来表示注释# - Blank lines are ignored # 空白行被忽略# - Groups of hosts are delimited by [header] elements # 主机组 需要在【】下面# - You can enter hostnames or ip addresses #可以写主机名或者ip地址# - A hostname/ip can be a member of multiple groups # 一台主机可以在多个组里面www[001:006].example.com #表示从www001到www006的机器 ansible 192.168.115.134 -m ping错误显示ssh连接出了问题,可以用
ansible 192.168.115.135 -m ping -k 带参数-k 可以通过输入密码进行连接如果不用此方法之后全部通过密钥先将所有的机器连接起来在通过第一种联通的方式去连接
ssh-copy-id 192.168.107.135 # 复制秘钥到远程主机1.全部
前提:都是密钥连接过的,而且写在 vi /etc/ansible//hosts #在这里面加入你要控制的机器ip 中的机器
ansible all -m ping2.个别 用逗号隔开即可
ansible 192.168.115.135,192.168.115.134 -m ping3.分组,按照功能进行分组
vi /etc/ansible//hosts #进入hosts文件进行分组利用多个分组 执行命令如下
ansible web,db -m ping假设是两个组里面的共同主机怎么办?
多个组
交集 ‘web:&db’
并集
web,db
‘web:db’
差集 ‘web:!db’
查看用户是否创建成功
tail -1 /etc/passwdtail -1 /etc/shadowid alexecho '123' | passwd --stdin alex #设置密码
补充
inode 硬盘的地址id 获取到的是内存的地址ln -s a.py b.py 创建软连接ln a.py c.py 创建硬链接当 源文件变化时,软连接和硬链接文件都会跟着变化 ansible db -m file -a 'path=/lzmly2 state=directory' #在远程机器上创建文件夹ansible db -m file -a 'path=/root/q.txt state=touch' #用来在远程机器上创建文件ansible db -m file -a 'path=/tmp/f src=/etc/fstab state=link' #创建软连接src是源地址,path是目标地址ansible db -m file -a 'path=/tmp/f state=absent' #用来删除文件或者文件夹ansible 安装 epel源
ansible-doc 查看模块的帮助信息
host-pattern格式
单个主机
全部主机 all表示
多个主机
单个组
多个组
交集 ‘web:&db’
并集
web,db
‘web:db’
差集 ‘web:!db’9o
命令相关模块
command 不支持特殊字符 <> |!;$&
shell
chdir 编译安装
creates 文件存在,则不执行
removes 文件存在,就执行
shell、python、ruby、perl 被管控机
script 执行管控机上的脚本
参数判断的是被管控机上的文件
文件相关的参数
copy
backup
src
dest
group
mode
owner
content
file
state
directory
touch
link
hard
absent
file
src
link
hard
path
fetch 以ip创建文件夹,并保存原来的目录结构
dest
src
9
转载于:https://www.cnblogs.com/RootEvils/p/10407253.html
相关资源:运维自动化之ANSIBLE.md