运维工具
系统备份和恢复
Clonezilla
install clonezilla network boot system
clonezilla push setting
clonezilla pxelinux.cfg default config
clonezilla pxe boot password
kickstart
kickstart centos5.6-i386 config
kickstart auto install
kickstart example
Cobbler
cobbler backups-restore
aomei 傲梅
傲梅集中备份
傲梅备份 分类
系统监控工具
collectd
collectd 收集系统性能
NMON monitor
Nmon monitor system
njmon script initd code
nmon 2 data to influx db
Zabbix
zabbix 3.2 install on centos 6
zabbix firewall
zabbix support windows
Supervisor
supervisor shell script
supervisor config example
boot supervisrd with systemd on centos7
webhook and github to do file sync with supervisor
日志管理系统
Grafana
grafana install on centos 6
grafana install plugin
grafana influx version
Filebeat
filebeat yum install
Kibana
kibana yum install
Logstash
logstash install on centos
Elasticsearch
yum install elasticsearch 6.8
elasticsearch install on Centos 6.7
ELK init env config
Elasticsearch 错误集锦
Rsyslog
centos 6 rsyslog 日志实时同步
Rsyslog mysql log to master analyzer
Deploy
Jumpserver
jumpserver 0.3.2 install on centos 6
jumpserver 0.3.2 docker install on centos 7
jumpserver 0.5 install on centos 7
Opsmanage
opsmanage install centos7
Jenkins
jenkins install on centos 6
install plugin in jenkins…
jenkins set time execution
tomcat jenkins ansible
jenkins ansible ad-hoc command
jenkins ansible playbook project
jenkins publish over_ssh
Paramike
PSSH
Centos7部署工具pssh
Ansible
how to install ansible with yum
bit rpm install ansible
source to install ansible
ansible init system centos 6
ansible using method
ansible install httpd servers
copy code with ansible-playbook
ansible ping host actived
ansible add username
ansible config parameter
ansible config write format
ansible api study
ansible hosts config ssh
ansible get nmon data
ansible setup filter information
yum repo with ansible-playbook
ansible gitlab ci runner
ansible get data list
ansible get text content
ansible get linux release debug infor
ansible support windows pywinrm
Saltshaker
saltshaker use docker
how to install saltstack
saltshaker manual install
salt install and config
salt init system
deploy saltshaker on centos7
salt file config desc
salt cmdb
saltshaker dj mq mysql build
salt data to mysql
Rsync
rsync + inotify 数据实时同步
代码仓库
Gitlab
yum install gitlab
gitlab-ce and runner
gitlib api example
gitlab config
gitlab ce and ee
Gogs
Gitea
虚拟化系统
Vmware
centos 6 install vmware 14
Vagrant
从零开始创建基础 Box
打包我的 BOX
Vagrantfile Config
Vagrant简易教程
给 Vagrant 从 VirtualBox换用 VMware 或 虚拟机
优化 vagrantFile config
Vagrant 主机定义
vagrant SSH
Vagrant 搭建 说明
WSL
pycharm 安装支持 WSL
windows-WSL 安装
Docker
how to install docker on centos 6
docker config source daoclound
how to use docker by step
how to creat docker subnet
gogs deploy on docker
jenkins use docker to deploy
mysql use docker to deploy
docker-example-1
docker-example-2
mac-osx-toolbox-install-docker
Data DB
Influx DB
InfluxDB install on centos
Mysql DB
centos 6 install mysql 5.5
mysql 5.7 install centos 6
install percona mysql 5.6 with yum
centos 7 install mysql config
mysql data rsync from master/slave
About me
本文档使用 MrDoc 发布
-
+
首页
ansible using method
# ansible using method Ansible模块介绍 ### 1、安装Ansible # yum -y install epel-release # yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto # yum -y install ansible # ansible --version ``` ansible 2.1.0.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides ``` SSH密钥 ### 2、设置SSH密钥 在Ansible服务端生成密钥,并且复制公钥到节点中。 # ssh-keygen -t rsa 使用ssh-copy-id命令来复制Ansible公钥到节点中。 # ssh-copy-id -i root@10.81.235.190 hosts ### 3、为Ansible定义节点清单 编辑文件/etc/ansible/hosts 维护着Ansible要管理的服务器清单 # vim /etc/ansible/hosts ``` [test] 10.81.235.190 10.81.235.195 10.81.235.200 ``` ==== ping ==== ### 4、尝试在Ansible服务端运行命令 使用ping检查‘docker-deploy’或者ansible节点的连通性 # ansible -m ping 'test' ``` 10.81.235.190 | SUCCESS => { "changed": false, "ping": "pong" } 10.81.235.195 | SUCCESS => { "changed": false, "ping": "pong" } 10.81.235.200 | SUCCESS => { "changed": false, "ping": "pong" } ``` 执行shell命令 例子1:检查Ansible节点的运行时间(uptime) ,由于这些模块均是默认的,因此可以不加-m 模块名称。 # ansible -m command -a "uptime" 'test' ``` 10.81.235.200 | SUCCESS | rc=0 >> 07:29:36 up 8 days, 26 min, 3 users, load average: 0.20, 0.19, 0.18 10.81.235.190 | SUCCESS | rc=0 >> 07:29:37 up 8 days, 4:32, 3 users, load average: 0.28, 0.23, 0.19 10.81.235.195 | SUCCESS | rc=0 >> 07:29:38 up 8 days, 4:32, 3 users, load average: 0.16, 0.17, 0.17 ``` 例子2:重定向输出到文件中 # ansible all -m command -a "df -Th" > ~/52opn.txt -k # cat ~/52opn.txt ``` 10.81.235.190 | SUCCESS | rc=0 >> Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 ext3 8.2G 3.1G 4.7G 41% / /dev/sda1 ext3 99M 13M 82M 13% /boot tmpfs tmpfs 252M 16K 252M 1% /dev/shm 10.81.235.195 | SUCCESS | rc=0 >> Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 ext3 8.2G 3.1G 4.7G 40% / /dev/sda1 ext3 99M 13M 82M 13% /boot tmpfs tmpfs 252M 16K 252M 1% /dev/shm 10.81.235.200 | SUCCESS | rc=0 >> Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 ext3 6.7G 3.0G 3.4G 47% / /dev/sda1 ext3 99M 13M 82M 13% /boot tmpfs tmpfs 252M 16K 252M 1% /dev/shm ``` ==== ansible常用模块 ==== ### 5、ansible常用模块 command #### 1、command:命令模块,默认模块,用于在远程执行命令,不支持变量。 # ansible 10.81.235.190 -a 'date' -k ``` 10.81.235.190 | SUCCESS | rc=0 >> Mon Aug 15 08:02:45 CST 2016 ``` ---- ===== cron ===== #### 2、cron:计划任务模块: # ansible test -m cron -a 'minute="*/10" job="/bin/echo "hello"" name="52opn web"' -k ``` #Ansible: 52opn web */10 * * * * /bin/echo "hello" ``` ---- user #### 3、user:用户管理模块: ansible webserver -m user -a 'name="node1" ' ---- ===== copy ===== ### 4、copy:远程复制模块 #### a、复制文件至远程主机: # ansible all -m copy -a 'src=/etc/vsftpd/vsftpd.conf dest=/etc/vsftpd owner=root mode=640' -k ``` 10.81.235.195 | SUCCESS => { "changed": false, "checksum": "2fb3723667a5ee43d828c0a580530ea2c2fd007a", "dest": "/etc/vsftpd/vsftpd.conf", "gid": 0, "group": "root", "mode": "0640", "owner": "root", "path": "/etc/vsftpd/vsftpd.conf", "size": 4629, "state": "file", "uid": 0 } ``` content #### b、往远程主机文件写入内容:使用content代替src。 # ansible all -m copy -a 'content="ansible test host" dest=/etc/my.cnf' -k ``` ansible test host ``` ---- ===== 文件属性 ===== ### 5、file:设置文件属性模块 #### a、设置指定文件属性: # ansible all -m file -a 'owner=tester group=tester mode=775 path=/usr/local/src/name.txt' -k ``` ll -rw-r--r-- 1 root root 14 Aug 15 06:37 name.txt ll -rwxrwxr-x 1 tester tester 14 Aug 15 06:37 name.txt ``` ===== 文件属性 link ===== #### b、创建文件符号链接: # ansible all -m file -a 'path=/usr/local/bin/ziplink src=/usr/bin/zip state=link' -k ``` total 0 lrwxrwxrwx 1 root root 12 Aug 15 08:52 ziplink -> /usr/bin/zip ``` ---- ### 6、ping:测试指定主机网络是否通讯: # ansible test -m ping ``` SSH password: 10.81.235.200 | SUCCESS => { "changed": false, "ping": "pong" } ``` ---- service ### 7、service:指定服务状态模块管理(必须保证远程主机事先安装好指定服务) * enabled:是否开机自动启动 true/false * name:服务名称 * start:状态,取值为startd,stopd,restartd # ansible all -m service -a 'enabled=true name=httpd state=started' -k ``` SSH password: 10.81.235.195 | SUCCESS => { "changed": false, "enabled": true, "name": "httpd", "state": "started" } ``` ---- shell模块 ### 8、shell模块: 在远程主机上运行命令,支持管道、变量等在使用复制命令时使用。 # ansible all -m shell -a '/sbin/ifconfig |grep "HWaddr" | awk "{print $5}"' -k ``` 10.81.235.200 | SUCCESS | rc=0 >> eth0 Link encap:Ethernet HWaddr 08:00:27:1F:F7:67 ``` ---- yum ### 9、yum:程序安装 name:指定要安装的程序包,可以带上版本号 state:preset,laster表示安装最新,absent卸载 # ansible all -m yum -a 'name=wget state=present' -k ``` 10.81.235.200 | SUCCESS => { "changed": false, "msg": "", "rc": 0, "results": [ "wget-1.11.4-2.el5_4.1.i386 providing wget is already installed" ] } ``` ---- setup ### 10、setup:收集远程主机的facts # ansible test -m setup 每个被管理节点在接受并运行管理命令之前,会将自己主机相关信息,操作系统版本、ip地址等会报告给ansible主机 用于将状态报告给ansible主机直接调用其变量。 ==== doc ==== ### 11、查看模块帮助命令: # ansible-doc -l ansible-doc -s Modules 查看支持模块 ```
Bobby
2021年12月20日 01:57
分享文档
收藏文档
阅读
111
上一篇
下一篇
微信扫一扫
复制链接
手机扫一扫进行分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码