回顾:pxe, ansible
pxe:
网卡支持网络引导;
dhcp, filename, next-server
tftp-server
pxelinux.0
vmlinuz, initrd.img
menu.c32
pxelinux.cfg/default
system-config-kickstart
ksvalidator
ansible:
os provision:
物理机:pxe, cobbler
虚拟机:image file template
configuration:
程序包管理、用户管理、配置文件、服务管理、cron任务等等;
puppet, saltstack, chef, cfengine
task exec
command and control
func, fabric
程序发布:灰度模型
agent
agentless:
ssh服务;
ansible:
ansible <host-pattern> [-f forks] [-m module_name] [-a args]
args:
key=value
注意:command模块要执行命令无须为key=value格式,而是直接给出要执行的命令即可;
常用模块:
command
-a ‘COMMAND‘
user
-a ‘name= state={present|absent} system= uid=‘
group
-a ‘name= gid= state= system=‘
cron
-a ‘name= minute= hour= day= month= weekday= job= user= state=‘
copy
-a ‘dest= src= mode= owner= group=‘
file
-a ‘path= mode= owner= group= state={directory|link|present|absent} src=‘
ping
没有参数
yum
-a ‘name= state={present|latest|absent}‘
service
-a ‘name= state={started|stopped|restarted} enabled=‘
shell
-a ‘COMMAND‘
script
-a ‘/path/to/script‘
setup
playbook的核心元素:
tasks: 任务
variables: 变量
templates: 模板
handlers: 处理器
roles: 角色
变量:
facts
--extra-vars "name=value name=value"
role定义
Inventory中的变量:
主机变量
hostname name=value name=value
组变量
[groupname:vars]
name=value
name=value
Inventory的高级用法:
Playbook:
- host:
vars:
remote_user:
tasks:
-
-
-
variables:
-
-
-
handlers:
-
-
- host:
- host:
"ansible_distribution_major_version": "7",
nginx.conf
worker_processes {{ ansible_processor_cores * ansible_processor_count - 1 }};
实战:用ansible playbook完成配置keepalived的集群;
博客:ansible的用法;
原文地址:https://www.cnblogs.com/hanshanxiaoheshang/p/10198689.html