3.2、Ansible单命令测试
0.Ansible的group支持all、通配符(*)、IP地址
1.查看Ansible的版本
$ ansbile --version
[root@test ~]# ansible --version
ansible 1.7.2
[root@test ~]#
2.消除首次ssh登录时要求输入yes确认
在所有机器上修改/etc/ssh/ssh_config文件中设置StrictHostKeyChecking no即可(默认为 ask )
[root@master ~]# grep "StrictHostKeyChecking" /etc/ssh/ssh_config
StrictHostKeyChecking no
3.拷贝文件
ansible <groupname> -m copy -a "src=/etc/ssh/ssh_config dest=/etc/ssh/ssh_config owner=root group=root mode=644 force=yes"
示例:
[root@test ~]# ansible all -m copy -a "src=/etc/ssh/ssh_config dest=/etc/ssh/ssh_config owner=root group=root mode=644 force=yes"
192.168.91.135 | success >> {
"changed": true,
"dest": "/etc/ssh/ssh_config",
"gid": 0,
"group": "root",
"md5sum": "d27d7cc9767512b64c84d06544e01546",
"mode": "0644",
"owner": "root",
"size": 2072,
"src": "/root/.ansible/tmp/ansible-tmp-1476168613.68-180284084445387/source",
"state": "file",
"uid": 0
}
[root@test ~]#
4.查看所有机器的磁盘情况
ansible <groupname> -m shell -a "df -h" -k
5.测试机器的连通性
ansible <groupname> -m ping
6.Ansible所有的模块
http://docs.ansible.com/ansible/list_of_all_modules.html
7.将本机上的配置文件组装发送到远程主机
ansible <groupname> -m assemble -a "src=/root/configure dest=/root/test/a.conf remote_src=False
8.将本机上的配置文件组装发送到远程主机,带分隔符
ansible <groupname> -m assemble -a "src=/root/configure dest=/root/test/a.conf remote_src=False delimiter='####'"
9.设定权限进行拷贝
ansible <groupname> -m copy -a "src=/root/configure/a.conf dest=/root/test owner=root group=root mode=0777"
10.拷贝的时候备份
ansible <groupname> -m copy -a "src=/root/kel/1 dest=/tmp/kel owner=root group=root backup=yes"
11.拷贝文件之后进行验证
ansible <groupname> -m copy -a "src=/etc/sudoers dest=/tmp/2 validate='visudo -cf %s'"
12. fetch一个文件进行保存
ansible <groupname> -m fetch -a "src=/root/123 dest=/root"
13.指定路径目录进行保存
ansible <groupname> -m fetch -a "src=/root/Ssh.py dest=/root/kel/ flat=yes"
14. 设置文件属性
ansible <groupname> -m file -a "path=/root/123 owner=kel group=kel mode=0644"
15.创建目录
ansible <groupname> -m file -a "path=/tmp/kel state=directory mode=0755"
16.修改权限
ansible <groupname> -m file -a "path=/tmp/kel mode=0444"
17.创建软连接
ansible <groupname> -m file -a "src=/tmp/1 dest=/tmp/2 owner=kel state=link"
18.添加其中的节的值
ansible <groupname> -m ini_file -a "dest=/tmp/kel section=kel option=kel value=kel mode=0600 backup=yes"
19.基础模块使用
19.1 并行和Shell命令
设置ssh-agent记住认证
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa
19.2 10秒内重启
$
ansible <groupname> -a "/sbin/reboot" -f 10
19.3 在默认情况下,ansible使用的是当前用户,当你需要使用其他用户的时候,可以使用选项-u
username
$ ansible <groupname> -a
"/usr/bin/foo" -u username
19.4 要使用sudo的时候
$
ansible <groupname> -a "/usr/bin/foo" -u username --sudo[--ask-sudo-pass]
--ask-sudo-pass(-K)此选项是用来询问sudo的密码,如果设置了,如果未设置,那么无需使用
19.5 也可以在sudo到别的用户来进行执行
$
ansible <groupname> -a "/usr/bin/foo" -u
username -U otheruser[--ask-sudo-pass]
参数-f 10表示并发进行,也就是10个进程同时运行,在使用的时候,默认的情况下为5,选择合适的数据,从而使得系统能够进行处理
参数-m表示选择的模块,在默认情况下,command是默认的模块
Command不适用于有shell变量的情况,也不适用于有管道符的情况,如果要使用此种情况,那么可以使用shell模块
19.6 使用Shell模块
$
ansible <groupname> -m shell -a 'echo $TERM'
20. 文件传输
20.1 传输文件到很多主机
$ ansible <groupname> -m
copy -a "src=/etc/hosts dest=/tmp/hosts"
20.2 修改用户和用户组权限
$ ansible <groupname> -m
file -a "dest=/srv/foo/a.txt mode=600"
$ ansible <groupname> -m
file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"
20.3 创建目录
$ ansible <groupname> -m
file -a "dest=/path/to/c mode=755 owner=mdehaan group=mdehaan
state=directory"
21. 管理包
21.1 确定一个包已经安装,但是不更新
$ ansible <groupname> -m
yum -a "name=acme state=present"
21.2 确定一个包安装的是指定版本
$ ansible <groupname>
-m yum -a "name=acme-1.5 state=present"
21.3 确定一个包是最新包
$ ansible <groupname>
-m yum -a "name=acme state=latest"
21.4 确定一个包未安装
$ ansible <groupname>
-m yum -a "name=acme state=absent"
22. 用户和用户组
22.1 创建用户和管理已经存在的用户和组
$ ansible <groupname>
-m user -a "name=foo password=<crypted password here>"
$ ansible <groupname>
-m user -a "name=foo state=absent"
23. 服务管理
23.1 确定一个服务正在运行
$ ansible <groupname> -m
service -a "name=httpd state=started"
23.2 重启一个服务
$ ansible <groupname>
-m service -a "name=httpd state=restarted"
23.3 确定一个服务是停止的
$ ansible <groupname>
-m service -a "name=httpd state=stopped"
24.限制后台运行时间
24.1 后台运行总是耗费比较长的时间,从而其状态在随后总是能够查看的,如果踢掉主机,又不想轮训
$ ansible <groupname>
-B 3600 -P 0 -a "/usr/bin/long_running_operation --do-stuff"
24.2 如果要检查服务的状态,可以使用模块async_status,传递job id
$ ansible <groupname>
-m async_status -a "jid=488359678239.2844"
24.3 轮训是内建的
$ ansible <groupname> -B
1800 -P 60 -a "/usr/bin/long_running_operation --do-stuff"
参数-B表示运行最多30分钟,30*60,-P 60 轮训其状态每60S,
当时间运行在-B参数后的时间之后,此服务会被停止运行。
可以使用参数—forksvalue,来确保服务尽快运行
25.收集信息
$ ansible <groupname> -m
setup
来自 <http://www.cnblogs.com/LuisYang/p/5961001.html>
3.2、Ansible单命令测试的更多相关文章
- Ansible学习记录四:单命令测试
0.Ansible的group支持all.通配符(*).IP地址 1.查看Ansible的版本 $ ansbile --version [root@test ~]# ansible --versi ...
- kafka单节点测试
======================命令====================== 启动zookeeper server bin/zookeeper-server-start.sh conf ...
- centos ansible常用命令
ansible在日常运维中经常使用,特别是批量执行多台服务器的时候,有效减小重复的操作成本,以下从安装到使用仅讲解工作中常用的几种方式,模块很多功能很强大,但不做全面讨论. ansible安装 在ce ...
- 用命令测试安装好的OpenStack环境
OpenStack三个节点icehouse-gre模式部署一文部署了一套OpenStack环境,接下来使用命令测试一遍. 首先要明确几个概念: 外网:可分配floating ip绑定到虚拟机,外部就可 ...
- USB系列之七:ASPI介绍及命令测试
在以前的一篇博文<关于构建DOS下编程平台的总结>中曾经介绍了一种在DOS下驱动U盘的方法,我们大致回顾一下.在config.sys中加入两个驱动程序,就可以驱动U盘:device = a ...
- ansible常用命令
一.ansible常用命令 一.ansible命令的常用参数 ansible 默认提供了很多模块来供我们使用.在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansib ...
- Linux下使用DD命令测试磁盘读写速度
dd是Linux/UNIX 下的一个非常有用的命令,作用是用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换,所以可以用来测试硬盘的读写能力~ 几种常见的DD命令,先看一下区别~ dd bs=6 ...
- Python实现telnet命令测试防火墙
Python实现telnet命令测试防火墙 telnet主要用于测试主机端口是否开通 ping主要是用来测试网络是否畅通和主机是否正在使用 使用Python实现Telnet测试主机端口是否开通的功能. ...
- phpSpider 单页测试_模拟登陆
<?php require './vendor/autoload.php'; use phpspider\core\phpspider; use phpspider\core\requests; ...
随机推荐
- [bzoj1084][SCOI2005]最大子矩阵_动态规划_伪·轮廓线dp
最大子矩阵 bzoj-1084 SCOI-2005 题目大意:给定一个n*m的矩阵,请你选出k个互不重叠的子矩阵使得它们的权值和最大. 注释:$1\le n \le 100$,$1\le m\le 2 ...
- gdb的follow-fork-mode使用以及多线程操作
对于多线程,如果希望让其他线程不执行,只有调试线程执行,使用 set scheduler-locking [on|off|step]
- oracle批量更新
oracle批量更新 学习了:http://blog.csdn.net/zkcharge/article/details/50855755 statement.addBatch(); statemen ...
- [Angular] Increasing Performance by using Pipe
For example you make a function to get rating; getRating(score: number): string { let rating: string ...
- UVALive3938 "Ray, Pass me the dishes!" 线段树动态区间最大和
AC得相当辛苦的一道题.似乎不难,可是须要想细致, 開始的时候的错误思路----是受之前做过的区间最长连续子串影响http://blog.csdn.net/u011026968/article/det ...
- Node.js具体解析
介绍 JavaScript 高涨的人气带来了非常多变化.以至于现在使用其进行网络开发的形式也变得截然不同了.就如同在浏览器中一样,现在我们也能够在server上执行 JavaScript ,从前端跨越 ...
- Linux中的默认权限与隐藏权限(文件、文件夹)
一个文件(或文件夹)拥有若干个属性.包含(r/w/x)等基本属性,以及是否为文件夹(d)与文件(-)或连接文件(l)等属性.此外,Linux还能够设置其它系统安全属性.使用chattr来设置.以lsa ...
- nyoj170 网络的可靠性(第三届河南省程序设计大赛)
题目170 题目信息 执行结果 pid=170" style="text-decoration:none; color:rgb(55,119,188)">本题排行 ...
- Local Response Normalization作用——对局部神经元的活动创建竞争机制,使得其中响应比较大的值变得相对更大,并抑制其他反馈较小的神经元,增强了模型的泛化能力
AlexNet将LeNet的思想发扬光大,把CNN的基本原理应用到了很深很宽的网络中.AlexNet主要使用到的新技术点如下. (1)成功使用ReLU作为CNN的激活函数,并验证其效果在较深的网络超过 ...
- FastDFS介绍(非原创)
文章大纲 一.FastDFS介绍二.FastDFS安装与启动(Linux系统)三.Java客户端上传图片四.参考文章 一.FastDFS介绍 1. 什么是FastDFS FastDFS是用C语言编 ...