bluezone蓝域使用文档¶
【2020-12-30第2次修订】
公告:本文档属于个人文档,未经允许,不得私自传播!
作者:李亚津
联系QQ:838997384
专注与分享运维专业技术文档
说明:本文档并非最终版本,作者后期会进行适当的更新,本文档最终解释权归作者所有。
理论知识汇总1¶
蓝域是什么¶
蓝域是基于ansible底层实现得自动化管理工具
蓝域有什么用¶
蓝域可以实现服务器得远程批量管理,批量执行脚本,批量执行ansible playbook role ,资产主机组管理,跳板机管理,云管理等功能,随着后续得开发会加入更多得功能
蓝域得优缺点¶
优点:
- 无需记住ansible繁多得自动化命令
- 中文提醒,引导式得提醒使用者完成自动化操作
- 操作简单便捷
缺点:
1.目前仅支持一层跳板机管理远端服务器
- 暂时无法实现跨跳板机管理服务器
蓝域得实际应用¶
- 大批量管理服务器物理机虚拟机
- 针对大批量服务器进行批量配置执行等操作
蓝域的模块介绍¶
<+ Ansible Base module +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
** config - 核心模块 管理配置所有模块配置
** arping - 部署模块 [ 配置正常 ] 检查网段IP模块
** action - 部署模块 [ 配置正常 ] 远程单台服务器执行脚本(实时预览进度)
** ping - 核心模块 [ 配置正常 ] 测试远程主机SSH连接性
** cmd - 核心模块 [ 配置正常 ] 执行命令至远程主机
** shell - 核心模块 [ 配置正常 ] 从脚本库中执行单个脚本至远程主机
** bash - 核心模块 [ 配置正常 ] 执行指定路径单个脚本至(远程or本地)
** scripts - 核心模块 [ 配置正常 ] 执行指定路径多个脚本至(远程or本地)
** copy - 核心模块 [ 配置正常 ] 复制指定路径文件到远程主机
** fetch - 部署模块 [ 配置正常 ] 拉取远端服务器文件至本地
** cmdb - 核心模块 [ 配置正常 ] 主机组资产管理
** jump - 核心模块 [ 配置正常 ] 跳板机功能
** logs - 核心模块 [ 配置正常 ] 蓝域模块执行路径日志查询
** roles - 核心模块 [ 配置正常 ] 远程执行ansible roles
** playbooks - 核心模块 [ 配置正常 ] 远程执行ansible playbooks
** task - 核心模块 [ 配置正常 ] task模块任务编排功能
** work - 核心模块 [ 配置正常 ] work模块任务编排功能组
<+ Cloud module ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
** vcman - 核心模块 [ 配置正常 ] vcenter管理
** vcenter - 部署模块 [ 配置正常 ] vcenter虚拟机管理
<+ System jicheng tools module +++++++++++++++++++++++++++++++++++++++++++++++>
** tools01 - 部署模块 [ 配置正常 ] ipmi常用工具集合模块
** tools02 - 部署模块 [ 配置正常 ] system常用工具集合模块
<+ System jicheng check module +++++++++++++++++++++++++++++++++++++++++++++++>
** hardware - 部署模块 [ 配置正常 ] 服务器硬件检查验收模块
** ipmi - 部署模块 [ 配置正常 ] 服务器BMC账户验收模块
<+ System jicheng scan module +++++++++++++++++++++++++++++++++++++++++++++++>
** baseline - 部署模块 [ 配置正常 ] 服务器基线安全加固与检查模块
** nessus - 部署模块 [ 配置正常 ] 服务器基线安全扫描模块
<+ System module ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
** install - 核心模块 [ 配置正常 ] 自动化装机相关模块
** network - 核心模块 [ 配置正常 ] 配网工具模块
** init - 核心模块 [ 配置正常 ] 基本优化模块
** name - 核心模块 [ 配置正常 ] 服务器主机名称更改模块
** keys - 部署模块 [ 配置正常 ] 服务器发送keys免密模块
** clean - 核心模块 [ 配置正常 ] 基本服务器清理模块
** check - 核心模块 [ 配置正常 ] 基本服务器检查模块
** info - 核心模块 [ 配置正常 ] 服务器基本信息查看
<+ Deploy module +++++++++++++++++++++++++++++++++++++++++++++++++++++>
** deploy - 部署模块 [ 配置正常 ] 部署模块集合
** jumpserver - 部署模块 [ 配置正常 ] 部署jumpserver服务
** ceph - 部署模块 [ 配置正常 ] 部署ceph集群模块
** openstack_n - 部署模块 [ 配置正常 ] os集群neutron架构部署模块
** openstack_n_kuo - 部署模块 [ 配置正常 ] os集群neutron架构扩容模块
<+ Auto deploy base module +++++++++++++++++++++++++++++++++++++++++++++++++++++>
** auto_install - 部署模块 [ 配置正常 ] 自动化装机
** auto_init - 部署模块 [ 配置正常 ] 自动化系统初始化
** auto_name - 部署模块 [ 配置正常 ] 自动化系统配置主机名称
** auto_keys - 部署模块 [ 配置正常 ] 自动化发送公钥KEYS
** auto_check - 部署模块 [ 配置正常 ] 自动化检查系统环境
<+ Auto deploy env module +++++++++++++++++++++++++++++++++++++++++++++++++++++>
** auto_pm_env - 部署模块 [ 配置正常 ] 自动化准备物理机基础环境(从装机前开始)
** auto_vm_env - 部署模块 [ 配置正常 ] 自动化准备虚拟机基础环境(从创建后开始)
** auto_deploy_ceph - 部署模块 [ 配置正常 ] 自动化部署ceph集群(从装机开始)
** auto_deploy_os_n - 部署模块 [ 配置正常 ] 自动化部署os集群neutron架构模块(从装机开始)
<+ Auto deploy env kuo module +++++++++++++++++++++++++++++++++++++++++++++++++++++>
** ceph_kuo_osd - 部署模块 [ 配置正常 ] 自动化部署ceph集群扩容osd(从装机开始)
** os_n_kuo_compute - 部署模块 [ 配置正常 ] 自动化部署os集群neutron架构扩容计算节点模块(从装机开始)
** os_n_kuo_network - 部署模块 [ 配置正常 ] 自动化部署os集群neutron架构扩容网络节点模块(从装机开始)
基础环境准备(env)¶
目录结构说明¶
Bluejin目录介绍详细说明
[root@localhost bluezone]# ll
total 8
drwxr-xr-x 2 root root 266 Dec 30 14:31 bin # 模块程序存放目录
drwxr-xr-x 3 1080 1080 56 Dec 30 14:07 code # 主机组脚本存放目录
drwxr-xr-x 2 root root 6 Dec 30 13:32 conf # 配置文件存放目录
drwxr-xr-x 2 1080 1080 19 Dec 30 13:36 host # ansible主机组存放目录
drwxr-xr-x 2 1080 1080 53 Dec 29 10:35 logs # 日志存放目录
-rw-r--r-- 1 root root 43 Dec 29 12:13 readme # 说明手册
-rwxr-xr-x 1 1080 1080 1785 Dec 30 13:51 run # 主程序
ansible目录介绍详细说明
[root@localhost bluezone]# ls -l code/ansible/
total 28
-rw-r--r-- 1 1080 1080 14359 Nov 25 2019 ansible.cfg # ansible配置文件
drwxr-xr-x 2 1080 1080 17 Dec 28 14:46 group_vars # ansible变量存放目录
drwxr-xr-x 2 1080 1080 57 Dec 28 17:36 playbooks # ansible playbooks 存放目录
drwxr-xr-x 4 1080 1080 49 Dec 28 14:59 roles # ansible roles 存放目录
下载地址¶
程序下载地址:
系统环境¶
系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
内核版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# uname -a
Linux localhost 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
虚拟机规格
8C16G 100GB系统盘
网卡要求:
装机网
openstack管理网
CN2网络
ceph管理网(可临时通过NAT或者YUM进行转发连接)
配置pip 源¶
清华pip (建议优先配置)
mkdir /root/.pip/ -p
cat >/root/.pip/pip.conf<<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
EOF
豆瓣pip
mkdir /root/.pip/ -p
cat >/root/.pip/pip.conf<<EOF
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
EOF
阿里云pip
mkdir /root/.pip/ -p
cat >/root/.pip/pip.conf<<EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
联网安装(centos7.6)¶
基础必备软件包安装
yum install -y subversion python-pip dos2unix ansible rsync vim tmux
config模块依赖包
pip install numpy==1.7.1
pip install pandas==0.24.2
pip install openpyxl==2.0.3
pip install xlrd==1.2.0
cmdb资产管理模块依赖包
pip install xlrd==1.2.0
pip install pandas==0.24.2
vcman模块依赖包
pip install utils==0.9.0
pip install xlwt==1.3.0
pip install pyVmomi==7.0
install模块依赖包
yum install -y dos2unix
ceph模块依赖包
yum -y install ceph-deploy
update模块依赖包
yum install -y subversion
本地安装(centos7.6)¶
YUM配置
rm -f /etc/yum.repos.d/*.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum repolist
本程序完美适配centos7.6版本,可使用以下命令进行本地安装,适用于无法联网的环境
mkdir -p /root/.work/
mkdir -p /root/.ssh/
chmod 600 /root/.ssh/
touch /root/.ssh/config
chmod 644 /root/.ssh/config
tar xf /root/bluezone-2022-04-08-oldjiagou.tar.gz -C /root/.work/
echo 'alias bluezone="cd /root/.work/bluezone ; ./run $1 $2 $3 $4 $5 $6 $7 $8 $9"' >>/etc/profile
source /etc/profile
cd /root/.work/bluezone/code/package/install/rpm
yum install -y subversion python-pip dos2unix ansible rsync vim tmux
cd /root/.work/bluezone/code/package/install/pip
yum -y install python-pip
pip install *.whl
pip install openpyxl-2.0.3.tar.gz
rm -f /root/bluezone-202*
cd /root/.work/bluezone
./run config all A-000-demo/ test_zone_env04.xlsx
sed -i "s@# store-plaintext-passwords = no@store-plaintext-passwords = no@g" /root/.subversion/servers
./run config all A-000-demo/ test_zone_env04.xlsx
安装自动化功能
bluezone auto_install cmdb 127.0.0.1 "1 2"
主机组配置¶
开始配置主机组
[root@localhost bluezone]# cat >host/nodes<<EOF
[test01]
10.0.194.131
10.0.194.132
10.0.194.133
# 请填写您准备好得机器列表即可
[all:vars]
# 远程ssh用户名称
ansible_ssh_user=root
# 远程ssh用户端口
ansible_ssh_port=10000
# 远程ssh用户密码
ansible_ssh_pass=www.123
EOF
主机组变量配置¶
配置ansible主机组全局变量
[root@localhost bluezone]# cat >code/ansible/group_vars/all<<EOF
---
ansible_base_path: '/home/test'
hostname_title: 'nm01'
tmp_yum_repo_host: '10.0.194.241'
tmp_ntp_server_host: '10.0.194.239'
public_yum_repo_host: '124.236.120.248:50001'
public_ntp_server_host: 'ntp1.aliyun.com'
ceph_yum_repo_host: '10.0.194.241'
ceph_ntp_server_host: '10.0.194.239'
yum_repo_host: '10.0.194.241'
ntp_server_host: '10.0.194.239'
dns_server_host: '114.114.114.114'
test_repo_name: 'centos-7.6-base.repo.j2'
auth_keys_file: '/root/.ssh/authorized_keys'
password_auth: 'no'
root_public_key: 'ssh-dss AAAAB3NzaC1kc3MAAACBAP7j/qY3A/98ZFolHd1WQ10GdpToxr7lDoNr0HUf6MVTbarDN0w6Q6UbKzy7E/JrIhoSs7i7ExGLofdPtDy17SrqWrRjaKmq4ybpc4TMD7iYDU1T0fe6jgMdmbTNXSEDjdYsHG9MVI18WebA5WxGLWNKfWbJ9gYC9CCE6sSXmwoJAAAAFQDOJl3Ao6hyWeubMJWkSDQcU9yzbQAAAIEA9mrWEInw5JAYCUBzqLC5pRZLv/h6CRh32WInoY4XTl1yfSMePoUQWI6uYbvpMlX5PtmF7AEWlV2SgObt9iVwSuNDH8/bxjN5K3vbdMqmPuegeUsBjLdCazQF4XiDMHZn56d8tSGc9MwpcTdAILsBDqrH5vElCfWQUK1mcmFYSpEAAACBAN6aPbM6T8a8avJ5CLMwUuOotQLjm13sXcEvVcoa3M6j9T/O39yfYYmwnw5DIBhzmCubt+x9EDbc+mEsimAbZ6hgHOd6YTSXdfrcuvhrxyE/WvKEo80InmrG2iWuFU5YV1LUWZPyNq3oAr/gV1Hm7/aimWQn3mx2f/1k7peJx7Zi root@beijing02-10e129e176e200'
root_public_key01: ''
root_public_key02: ''
root_public_key03: ''
root_passwd: 'www.123'
EOF
核心类模块详解(基础类型)¶
config模块¶
cmdb模块配置¶
init模块配置¶
ping模块¶
模块介绍:ping 模块可以测试服务器主机得ssh连接性 测试远程主机是否可以出外网,是否可以ping通域名排查dns解析问题
host功能¶
该功能可以测试远程主机得ssh连接
备注:绿色表示正常,红色表示失败
./run ping host nodes test01
dns功能¶
该功能可以测试远程主机是否可以ping通114.114.114.114
备注:绿色表示正常,红色表示失败
./run ping dns nodes test01
www功能¶
该功能可以测试远程主机是否可以ping通www.baidu.com
备注:绿色表示正常,红色表示失败
./run ping www nodes test01
host_all功能¶
该功能可以测试统计所选择主机组得服务器SSH连接性,并打印统计报告
./run ping host_all nodes test01
cmd模块¶
模块介绍:cmd 模块可以实现在本地服务器执行命令到远程服务器
执行方式1(单独执行¶
./run cmd 'date' nodes test01
执行方式2(多命令执行¶
./run cmd 'date +%F_%T && hostname' nodes test01
shell模块¶
模块介绍:shell模块可以实现本地服务器上代码库中code/shell/指定目录下存放得脚本可以到远程服务器上执行
准备脚本¶
cat >code/shell/1.sh<<EOF
#!/bin/bash
pwd
date
ls -l /root
EOF
cat code/shell/1.sh
执行方式1(前缀执行¶
./run shell 'sh 1.sh' nodes test01
执行方式2(单独执行¶
./run shell './1.sh' nodes test01
执行方式3(传参方式¶
./run shell 'sh 1.sh canshu' nodes test01
清理测试脚本¶
rm -f code/shell/1.sh
bash模块¶
模块介绍:bash模块可以实现将本地指定路径得脚本再本地执行,或者复制到远程主机上执行
准备脚本环境¶
准备测试shell脚本
cat >test.sh<<EOF
hostname
lsblk
EOF
cat >/tmp/test.sh<<EOF
hostname
lsblk
EOF
chmod +x test.sh /tmp/test.sh
准备测试python脚本
cat >test01.py<<EOF
#!/usr/bin/python
# -*- coding: UTF-8 -*-
print( "hello beijing" )
EOF
cat >/tmp/test01.py<<EOF
#!/usr/bin/python
# -*- coding: UTF-8 -*-
print( "hello beijing" )
EOF
chmod +x test01.py /tmp/test01.py
本地执行脚本¶
本地执行单个shell脚本
./run bash local './test.sh'
./run bash local '/tmp/test.sh'
./run bash local 'sh ./test.sh'
./run bash local 'sh /tmp/test.sh'
./run bash local 'sh ./test.sh canshu'
./run bash local 'sh /tmp/test.sh canshu'
本地执行单个python脚本
./run bash local './test01.py'
./run bash local '/tmp/test01.py'
./run bash local 'python ./test01.py'
./run bash local 'python /tmp/test01.py'
./run bash local 'python ./test01.py canshu'
./run bash local 'python /tmp/test01.py canshu'
远程执行脚本¶
远程执行单个shell脚本
./run bash remote './test.sh' nodes test01
./run bash remote '/tmp/test.sh' nodes test01
./run bash remote 'sh ./test.sh' nodes test01
./run bash remote 'sh /tmp/test.sh' nodes test01
./run bash remote 'sh ./test.sh canshu' nodes test01
./run bash remote 'sh /tmp/test.sh canshu' nodes test01
远程执行单个python脚本
./run bash remote './test01.py' nodes test01
./run bash remote '/tmp/test01.py' nodes test01
./run bash remote 'python ./test01.py' nodes test01
./run bash remote 'python /tmp/test01.py' nodes test01
./run bash remote 'python ./test01.py canshu' nodes test01
./run bash remote 'python /tmp/test01.py canshu' nodes test01
清理脚本环境¶
以上测试完毕后将多余得测试脚本清理删除即可
rm -f test01.py test.sh /tmp/test.sh /tmp/test01.py
scripts模块¶
模块介绍:scripts 模块可以实现脚本集合在本地或者远程服务器执行
准备脚本环境¶
准备测试shell脚本(模拟实现脚本嵌套集合)
mkdir /tmp/scripts -p
cd /tmp/scripts/
echo "echo this is test01" >test01.sh
echo "sh test02.sh" >>test01.sh
echo "sh test03.sh" >>test01.sh
echo "echo this is test02" >test02.sh
echo "echo this is test03" >test03.sh
chmod +x test01.sh test02.sh test03.sh
sh test01.sh
cd -
本地执行脚本¶
本地执行多个shell脚本集合
./run scripts local /tmp/scripts/ 'test01.sh'
./run scripts local /tmp/scripts/ './test01.sh'
./run scripts local /tmp/scripts/ 'sh ./test01.sh'
./run scripts local /tmp/scripts/ 'sh ./test01.sh canshu'
./run scripts local /tmp/scripts/ 'sh ./test01.sh ; sh ./test02.sh'
远程执行脚本¶
远程执行多个shell脚本集合
./run scripts remote /tmp/scripts 'test01.sh' nodes test01
./run scripts remote /tmp/scripts './test01.sh' nodes test01
./run scripts remote /tmp/scripts/ 'sh test01.sh' nodes test01
./run scripts remote /tmp/scripts/ 'sh test01.sh ; sh test02.sh ' nodes test01
清理测试脚本¶
rm -rf /tmp/scripts
copy模块¶
模块介绍:copy模块可以实现将本地服务器上得文件复制到远程服务器
执行方式1(绝对路径¶
./run copy '/etc/services /tmp/' nodes test01
执行方式2(相对路径¶
touch test.sh
./run copy './test.sh /tmp/' nodes test01
rm -f test.sh
cmdb模块¶
资产表格上传目录¶
[root@neimeng01 bluezone]# ll cmdb/xlsx/
total 1104
-rw-r--r-- 1 root root 1129555 Jan 4 11:07 A-004-neimeng01.xlsx
资产表格上传格式¶
list功能¶
[root@neimeng01 bluezone]# ./run cmdb
## 请选择你需要加载得主机表格名称,可选择得主机表格如下:
neimeng01
[root@neimeng01 bluezone]# ./run cmdb neimeng01 list
reload功能¶
[root@neimeng01 bluezone]# ./run cmdb neimeng01 reload
jump模块¶
ssh功能¶
[root@neimeng01 bluezone]# jump
## 请选择你需要加载得主机表格名称,可选择得主机表格如下:
neimeng01
[root@neimeng01 bluezone]# jump neimeng01
reload | ssh
[root@neimeng01 bluezone]# jump neimeng01 ssh
[root@neimeng01 bluezone]# jump neimeng01 ssh 4_neimeng01_keyong_nodes_compute_nodes
######################################
[root@10e0e190e5 ~]#
logs模块¶
查询最近日志¶
[root@neimeng01 bluezone]# ./run logs
请输入你需要查看最近多少条日志 【 1 - 9999 】
输入 【 all 】 可以查询所有日志
[root@neimeng01 bluezone]# ./run logs 10 # 查询最近n条日志
查询所有日志¶
[root@neimeng01 bluezone]# ./run logs all
查询模块日志¶
查看模块执行日志
[root@neimeng01 bluezone]# ./run logs 10
2021-01-07-15-46-37 neimeng01 [ SUCCESS ] cat /root/bluezone/logs/module_log/2021-01-07/2021-01-07-15-46-37 ./run scripts 'remote' '/tmp/scripts' './test01.sh' nodes nodes test01
2021-01-07-15-46-41 neimeng01 [ SUCCESS ] cat /root/bluezone/logs/module_log/2021-01-07/2021-01-07-15-46-41 ./run scripts 'remote' '/tmp/scripts/' 'sh test01.sh' nodes nodes test01
2021-01-07-15-46-48 neimeng01 [ SUCCESS ] cat /root/bluezone/logs/module_log/2021-01-07/2021-01-07-15-46-48 ./run scripts 'remote' '/tmp/scripts/' 'sh test01.sh ; sh test02.sh ' nodes nodes test01
查看模块详细日志
cat /root/bluezone/logs/module_log/2021-01-07/2021-01-07-15-46-48
2021-01-07 15:46:50,174 p=45745 u=root | 10.0.194.131 | SUCCESS => {
"changed": true,
"checksum": "a7d01fd9bfba613883ee13f68804fc7c459c6cd3",
"dest": "/tmp/scpipts_tmp.tar.gz",
"gid": 0,
"group": "root",
"md5sum": "e2c37976d30cfa9602f1693deffa1d11",
"mode": "0655",
"owner": "root",
"size": 205,
"src": "/root/.ansible/tmp/ansible-tmp-1610005609.22-170135423906505/source",
"state": "file",
"uid": 0
}
2021-01-07 15:46:51,905 p=45843 u=root | 10.0.194.132 | SUCCESS | rc=0 >>
this is test01
this is test02
this is test03
this is test02
核心类模块详解(编排类型)¶
task模块¶
准备环境¶
准备环境01(无变量模式)
cat >conf/task.conf <<EOF
#!/bin/bash
task01 , ./run ping host cmdb test01 , 备注
task02 , ./run ping host cmdb test02 , 备注
task03 , ./run ping host cmdb test03 , 备注
task04 , ./run ping host cmdb test04 , 备注
EOF
准备环境02(变量混合模式)
vim conf/task_01.conf
#!/bin/bash
ansible_hosts="cmdb"
ansible_nodes="test01"
task01 , ./run ping host $ansible_hosts test01 , 备注
task02 , ./run ping host $ansible_hosts $ansible_nodes , 备注
task03 , ./run ping host $ansible_hosts test03 , 备注
task04 , ./run ping host nodes test01 , 备注
执行方式1(执行单个task方式¶
./run task default run task01
./run task default run 1
./run task conf/task_01.conf run task01
./run task conf/task_01.conf run '1'
执行方式2(执行多个task方式¶
./run task default run 'task01 task02 task03'
./run task default run '1 3 2'
./run task conf/task.conf run 'task01 task02 task03'
./run task conf/task.conf run '1 3 2'
执行方式3(执行所有task方式¶
该模式可以将指定得task配置文件得所有task按照顺序依次进行执行
./run task default run all
./run task conf/task.conf run all
work模块¶
准备环境¶
准备环境01(无变量模式)
cat >conf/task.conf <<EOF
#!/bin/bash
task01 , ./run ping host nodes test01 , 备注
task02 , ./run ping host nodes test02 , 备注
task03 , ./run ping host nodes test03 , 备注
task04 , ./run ping host nodes test04 , 备注
EOF
准备环境02(变量混合模式)
vim conf/task_01.conf
#!/bin/bash
ansible_hosts="nodes"
ansible_nodes="test01"
task01 , ./run ping host $ansible_hosts test01 , 备注
task02 , ./run ping host $ansible_hosts $ansible_nodes , 备注
task03 , ./run ping host $ansible_hosts test03 , 备注
task04 , ./run ping host nodes test01 , 备注
EOF
准备环境03(变量混合模式)
vim conf/task_02.conf
#!/bin/bash
ansible_hosts="nodes"
ansible_nodes="test01"
task01 , ./run ping host $ansible_hosts test01 , 备注
task02 , ./run ping host $ansible_hosts $ansible_nodes , 备注
task03 , ./run ping host $ansible_hosts test03 , 备注
task04 , ./run ping host nodes test01 , 备注
现在我们开始准备work配置文件
cat >conf/work.conf<<EOF
#!/bin/bash
work_name01 , conf/task.conf , 备注
work_name02 , conf/task_01.conf , 备注
work_name03 , conf/task_02.conf , 备注
EOF
cat >conf/work_01.conf<<EOF
#!/bin/bash
work_name01 , conf/task.conf , 备注
work_name02 , conf/task_01.conf , 备注
EOF
执行方式1(执行单个work中单个task¶
./run work default run work_name01 task01
./run work default run 1 1
./run work conf/work_01.conf run work_name01 task01
./run work conf/work_01.conf run 1 1
备注:支持work序号work名称task序号task名称(default表示使用默认得wrok配置文件)
执行方式2(执行单个work中多个task¶
./run work default run work_name01 'task01 task03 task04'
./run work default run 1 '1 3 4'
./run work conf/work_01.conf run work_name01 'task01 task03 task04'
./run work conf/work_01.conf run 1 '1 3 4'
备注:支持work序号work名称task序号task名称(default表示使用默认得wrok配置文件)
执行方式3(执行单个work中所有task¶
./run work default run 'work_name01' 'all'
./run work default run '1' 'all'
./run work conf/work_01.conf run 'work_name01' all
./run work conf/work_01.conf run 1 all
自动化类模块详解(ansible)¶
roles模块¶
模块介绍:roles 模块可以实现将本地得ansible roles远程执行
执行方式1(执行所有task任务¶
[root@neimeng01 bluezone]# bluezone roles
请指定ansible脚本家目录文件地址
[root@neimeng01 bluezone]# bluezone roles code/ansible/
请您指定需要执行得roles角色名称 可以从以下角色中选择
system_env_check
system_env_clean
system_init
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init
## 请设置ansible host文件位置,有以下文件可以提供您选择
neimeng01_host_list_all
nodes
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes
## 请设置您需要执行的ansble主机组,以下主机组可以提供您选择
[test01]
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes test01
请选择是否单独执行该角色得tags 如果只执行该角色 选择 all 即可 ,当前也可以选择如下tags执行即可
add_user
Clean_all_repo
cmd_history
cmd_timeout
disable_selinux
dns_config
dns_kernel_update
exit_root_tty
history_clean
limits_config
ntp_config
send_ssh_authkey
set_passwd
sshd_config
sysctl_config
Update_yum_cache
yum_repo_config
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes test01 all
执行方式2(执行task任务指定tags¶
[root@neimeng01 bluezone]# bluezone roles
请指定ansible脚本家目录文件地址
[root@neimeng01 bluezone]# bluezone roles code/ansible/
请您指定需要执行得roles角色名称 可以从以下角色中选择
system_env_check
system_env_clean
system_init
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init
## 请设置ansible host文件位置,有以下文件可以提供您选择
neimeng01_host_list_all
nodes
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes
## 请设置您需要执行的ansble主机组,以下主机组可以提供您选择
[test01]
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes test01
请选择是否单独执行该角色得tags 如果只执行该角色 选择 all 即可 ,当前也可以选择如下tags执行即可
add_user
Clean_all_repo
cmd_history
cmd_timeout
disable_selinux
dns_config
dns_kernel_update
exit_root_tty
history_clean
limits_config
ntp_config
send_ssh_authkey
set_passwd
sshd_config
sysctl_config
Update_yum_cache
yum_repo_config
[root@neimeng01 bluezone]# bluezone roles code/ansible/ system_init nodes test01 ntp_config
playbooks模块¶
模块介绍:playbooks 模块可以实现将本地得ansible playbooks远程执行
准备环境¶
环境准备1 当playbooks主机组指定得为变量得环境
cat >code/ansible/test.yml<<EOF
- hosts: '{{ nodes }}'
gather_facts: no
tasks:
- name: lsblk
shell: lsblk
tags: lsblk
- name: date
shell: date
tags: date
EOF
环境准备2当playbooks主机组指定得为主机组得环境
cat >code/ansible/test01.yml<<EOF
- hosts: test01
gather_facts: no
tasks:
- name: lsblk
shell: lsblk
tags: lsblk
- name: date
shell: date
tags: date
EOF
执行方式1(执行所有task任务¶
[root@neimeng01 bluezone]# ./run playbooks
请指定ansible脚本家目录文件地址
[root@neimeng01 bluezone]# ./run playbooks code/ansible/
请您指定需要执行得playbooks文件路径 您可以从目前搜索到得playbooks中选择
./playbooks/system_env_check.yml
./playbooks/system_env_clean.yml
./playbooks/system_init.yml
./test.yml
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml
## 请设置ansible host文件位置,有以下文件可以提供您选择
neimeng01_host_list_all
nodes
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml nodes
## 请设置您需要执行的ansble主机组,以下主机组可以提供您选择
[test01]
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml nodes test01
请选择是否单独执行该playbooks 得tags 如果只执行该角色 选择 all 即可 ,当前也可以选择如下tags执行即可
date
lsblk
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml nodes test01 all
执行方式2(执行task任务指定tags¶
[root@neimeng01 bluezone]# ./run playbooks
请指定ansible脚本家目录文件地址
[root@neimeng01 bluezone]# ./run playbooks code/ansible/
请您指定需要执行得playbooks文件路径 您可以从目前搜索到得playbooks中选择
./playbooks/system_env_check.yml
./playbooks/system_env_clean.yml
./playbooks/system_init.yml
./test.yml
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml
## 请设置ansible host文件位置,有以下文件可以提供您选择
neimeng01_host_list_all
nodes
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml nodes
## 请设置您需要执行的ansble主机组,以下主机组可以提供您选择
[test01]
[root@neimeng01 bluezone]# ./run playbooks code/ansible/ ./test.yml nodes test01
请选择是否单独执行该playbooks 得tags 如果只执行该角色 选择 all 即可 ,当前也可以选择如下tags执行即可
date
lsblk
[root@neimeng01 bluezone]#./run playbooks code/ansible/ ./test.yml nodes test01 date
云管理类模块详解(cloud)¶
vcman模块¶
vcman模块:可以对vcenter集群进行检查,查看更新,虚拟机
配置文件说明¶
[root@neimeng01 bluezone]# cat conf/vcenter_list.conf
#
005 neimeng01_02 neimeng01_02 all 10.0.194.242 administrator@os.com passwd
015 hubei02 hubei02 all 10.252.224.242 administrator@os.com passwd
016 hunan03 hunan03 all 10.252.205.242 administrator@os.com passwd
check功能¶
./run vcman default check neimeng01_02
./run vcman conf/vcenter_list.conf check neimeng01_02
list功能¶
./run vcman default list neimeng01_02
./run vcman conf/vcenter_list.conf list neimeng01_02
reload功能¶
./run vcman default reload neimeng01_02
./run vcman conf/vcenter_list.conf reload neimeng01_02
系统类模块详解(system)¶
环境准备¶
配置需要操作得服务器机器
[root@localhost bluezone]# cat hosts/nodes
[test01]
10.0.194.131
10.0.194.132
10.0.194.133
[all:vars]
ansible_ssh_user=root
ansible_ssh_port=10000
ansible_ssh_pass=www.123
若想使用系统模块init则先需要配置ansible全局变量,变量配置如下
[root@localhost bluezone]# code/ansible/group_vars/all
---
# system init size percentage
ansible_base_path: /home/test # ansible基本目录地址
yum_repo_host: '10.0.194.241' # YUM仓库地址
ntp_server_host: '10.0.194.239' # NTP地址
dns_server_host: '114.114.114.114' # DNS地址
test_repo_name: 'centos-7.6-base.repo.j2' # YUM配置文件名称
# Safety reinforcement related configuration
auth_keys_file: '/root/.ssh/authorized_keys' #公钥key文件保存地址
password_auth: 'no' #是否允许密码登录,默认不允许
root_passwd: 'Tianyiyun0512' # 设置root密码
root_public_key: 'ssh-dss AAAAB3NzaC1kc3MAAACBANrWDNf1PuhVQ8ZLqROSfr+1/WQt6/Aiugy33eTVSNzx92WHUYyr6mPgbC06qnvNtqM8ooo/1BOHupvwQILu2DozBA+VaZQ7j56nxu8hy2irWWPapNGG3X63Jfd0L0zMOhJkDNB0WmAGDB2u4VNMDviubXMbUEqQVk7y/yIv/DwvAAAAFQD83RHhybSqDQOl1mrLhHKnvfbFwQAAAIBUH9agETQi/mTV7OlYpGK05zks6NfxQI9BLsp2UbTByPMD8jQoIxyfh1QM1zhpo/EaZMg6AcDFzJk2hEMlIx9YBj/sQK/AyWcxmzOqcEPTusuEE5S48iXpiLRkUb0Tf3qt25qZ9WFx8Ia/qf/Q4MsxKBcim5y+Vkb9XbkCV0N7JgAAAIEAwHISkW19VlQZ4XcFhbawci1FfyGzI0rnk9POPLJJn+NEC4GDrVAjIa28B2dSikGrSsZqk0oj6NyaWgKzFlj781FW5Uw6UyYnXQFB7qhlZh+bmGB7C+sAmpVxx1rXXPCR3P6aD9KR9dw6pY6V7SMx8T+SKxyKHmYw7EfCFD61K1Y= root@10-0-192-11' # 公钥key设置
root_public_key01: ''
root_public_key02: ''
cobbler模块¶
ipmi模块¶
network模块¶
init模块¶
模块介绍:init模块可以实现对服务器系统进行初始化操作
执行方式1(系统基础优化)¶
./run init mini_init nodes test01
执行方式2(指定tags方式1¶
./run init tags nodes test01 Clean_all_repo
执行方式2(指定tags方式2¶
./run init tags nodes test01 'Clean_all_repo ntp_config'
执行方式2(指定tags方式3¶
./run init tags nodes test01 'all'
备注:all表示执行该roles得所有task任务
name模块¶
clean模块¶
模块介绍:clean模块可以实现对系统服务器得基础清理工作
执行方式1(系统日志文件清理)¶
./run clean mini_init nodes test01
错误方式1(执行失败得情况¶
./run clean mini_init nodes test01
红色提醒:若出现以上报错则表示该服务器目前已经打开 3 个端口,端口分别为:[ 10000 123 80 ] 疑似已经部署了业务,需要您再确认下,为了安全终止了您本次的清理操作
check模块¶
模块介绍:check检查系统基础优化是否符合交付标准
执行方式1(系统基础优化检查¶
./run check mini_init nodes test01
执行方式2(检查服务器是否已使用¶
./run check no_use nodes test01
红色部分表示:该服务器目前已经打开 3 个端口,端口分别为:[ 10000 123 80 ] 疑似已经部署了业务,需要您再确认下
错误问题汇总(模块问题汇总)¶
常见错误1(config模块相关¶
问题现象1(执行config模块导致)
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://39.97.102.162:3690> /var/svn/system/system
can only be stored to disk unencrypted! You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible. See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? svn: E070014: Can't read stdin: End of file found
解决方法:
[root@neimeng01 bluezone]# vim /root/.subversion/servers
[global]
store-plaintext-passwords = no #取消此行注释