ansibles的hoc命令行

ansible

Ansible:Ansible的核心程序
Python
Paramiko
Jiaja2
Yam1

Host Lnventory:记录了每一个由Ansible管理的主机信息,信息包括ssh端口,root帐号密码,ip地址等等。可以通过file来加载,可以通过CMDB加载
Playbooks:YAML格式文件,多个任务定义在一个文件中,使用时可以统一调用,“剧本”用来定义那些主机需要调用那些模块来完成的功能.
Core Modules:Ansible执行任何管理任务都不是由Ansible自己完成,而是由核心模块完成;Ansible管理主机之前,先调用core Modules中的模块,然后指明管理Host Lnventory中的主机,就可以完成管理主机。
Custom Modules:自定义模块,完成Ansible核心模块无法完成的功能,此模块支持任何语言编写。
Connection Plugins:连接插件,Ansible和Host通信使用
 
1.Ansible优点:
• Stupied Simple ,上手简单,学习曲线平滑
• SSH by default ,安全,无需安装客户端
• 配置简单、功能强大、扩展性强
• 支持API及自定义模块,可通过Python轻松扩展
• 通过Playbooks来定制强大的配置、状态管理
• 提供一个功能强大、操作性强的Web管理界面和REST API接口——AWX平台
• 幂等性:一种操作重复多次结果相同
2.ansible安装
1. yum install epel-release
2. yum install ansible -y
3.ansible配置客户端(无密码登录)
第一种方法:
1. server: ssh-keygen
2. scp id_rsa.pub [email protected]:/root/.ssh/authorized_keys
第二种方法:
1.vim /etc/ansible/hosts
[zxw]
192.168.126.7 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123
192.168.126.6 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123
~
 3.三种模式
hoc:命令
palybooks:剧本:脚本
Roles : 角色
4.ansible常用命令
• ansible-doc -l #查看支持的模块
• ansible-doc -s MODEL_NAME #查看模块用法
• ansible命令应用基础
1. ansible <host-pattern> [options]
-f forks:启动并发线程数 默认并发数:5个
-m model_name:要使用的模块
-a args:特有的参数
• ansible zxw -m ping #查看client端是否正常ping通客户端p
192.168.126.7 | FAILED! => {
"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host‘s fingerprint to your known_hosts file to manage this host."
}
从输出提示上基本可以了解到由于在本机的~/.ssh/known_hosts文件中并有fingerprint key串,ssh第一次连接的时候一般会提示输入yes 进行确认为将key字符串加入到 ~/.ssh/known_hosts 文件中

基于这个原因,可以修改/etc/ansible/ansible.cfg配置文件

[[email protected] ~]# vim /etc/ansible/ansible.cfg

# uncomment this to disable SSH key host checking
host_key_checking = False
• ansible webserver -m setup #查看客户端信息
• ansible webserver -m copy -a ‘src=/root/git_test/code.txt dest=/root/test‘ #copy文件到cient端
[[email protected] ~]# ansible zxw -m copy -a ‘src=/root/zxw dest=/root/‘
组名 -m‘模块 -a 参数 (原文件 ,目标文件)
• ansible webserver -m user -a "name=test state=present" #创建test用户

• ansible webserver -m user -a "name=test state=absent" #删除test用户
• ansible webserver -m yum -a ‘name=epel-relese state=latest‘ #yum安装
[[email protected] ~]# ansible zxw -m service -a ‘name=network state=started‘

启动
[[email protected] ~]# ansible zxw -m service -a ‘name=network state=stoped‘
关闭
[[email protected] ~]# ansible zxw -m service -a ‘name=network state=retarted‘
重启
• ansible webserver -m script -a ‘/tmp/test.sh‘ #运行脚本
• ansible webserver -m command ‘date‘ #查看时间
[[email protected] ~]# ansible zxw -m command -a ‘date "+%F %T"‘
组名 -m 模块 -a ‘命令’
命令警告
[[email protected] ~]# vim /etc/ansible/ansible.cfg
# instead of shelling out to the git command.
command_warnings = False
打开注释

原文地址:https://www.cnblogs.com/itzhao/p/11262003.html

时间: 2024-07-30 14:43:44

ansibles的hoc命令行的相关文章

ansible-hoc命令行

ansible一种开源的自动化工具 ansible: hoc命令行: 是一款开源的自动化运维工具 python paramiko #模拟ssh协议批量管理主机 jinja2 #模板语言,主要用来传递变量 yaml #相当于是一种编程语言 控制方式: 1. 免密钥:key-gen 参数形式:ansible_ssh_user=root; ansible_ssh_pass=root ansible_ssh_port=22 2. host inventory:记录着客户端的ip信息 调用ansible的

数据仓库之抽取数据:通过bcp命令行导入数据

原文:数据仓库之抽取数据:通过bcp命令行导入数据 在做数据仓库时,最重要的就是ETL的开发,而在ETL开发中的第一步,就是要从原OLTP系统中抽取数据到过渡区中,再对这个过渡区中的数据进行转换,最后把经过处理的干净的数据加载到数据仓库中. 目标数据库是sql server,通过bcp命令行导入数据.bcp方式相对于其他方式来说,速度更快,是做了优化的. 以下为bcp命令行常用的参数,注意大小写: -c  以char作为存储类型 -w  和-c类似,只有当使用unicode字符集拷贝数据时使用n

【Windows10&nbsp;IoT开发系列】Powershell命令行实用程序

原文:[Windows10 IoT开发系列]Powershell命令行实用程序 更新帐户密码: 强烈建议你更新默认的管理员帐户密码.若要更新帐户密码,你可以发出以下命令: net user Administrator [new password]​ (其中 [new password] 表示你选择的强密码). 创建本地用户帐户: 如果你想要授予其他人访问你的 Windows IoT Core 设备的权限,你可以通过在 net user [username] [password] /add​ 中键

windows下cmd命令行显示UTF8字符设置(CHCP命令)

在中文windows系统中,如果一个文本文件是utf-8编码的,那么在cmd.exe命令行窗口(所谓的dos窗口)中不能正确显示文件中的内容.在默认情况下,命令行窗口中使用的代码页是中文或者美国的,即编码是中文字符集或者西文字符集. 如果想正确显示UTF-8字符,可以按照以下步骤操作: 1.打开CMD.exe命令行窗口 2.通过 chcp命令改变代码页,UTF-8的代码页为65001 1 chcp 65001 执行该操作后,代码页就被变成UTF-8了.但是,在窗口中仍旧不能正确显示UTF-8字符

CentOS设置默认启动命令行(不启动图形界面)

CentOS中如何进入图形界面和文字界面,Linux真正的服务器是不会运行图形化界面的,怎么样才能在不卸载桌面的前提下开机直接进入命令界面呢?(我安装的是CentOS 6.5)下面就简单介绍以下: 一.如果要进入图形界面: 1.首先得安装有图形界面,一般为X-window图形界面. 2.启动linux在终端下输入:startx 即可进入X11的图形操作界面. 二.在图形界面还可以在多个界面中进行切换: 在X-window图形操作界面中按"Alt+Ctrl+功能键Fn n=1~6 "就可

如何编写一个带命令行参数的Python文件

看到别人执行一个支持命令行参数的python文件,瞬间觉得高大上起来.牛逼起来,那么如何编写一个带命令行参数的python脚本呢?不用紧张,下面将简单易懂地让你学会如何让自己的python脚本,支持命令行参数. 首先你要知道python中的sys模块的一些功能: import sys print "the number of python program's argument:",len(sys.argv) print "the value of every argument

JNI之——在cmd命令行下编译执行C/C++源文件

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46604269 一直用java来敲代码,java配置好jre路径之后.在cmd下编译执行.非常方便. 刚好要给一个舍友改下C程序,想到可不能够像java一样在环境变量里配置好C的编译路径呢? 于是上网搜了一下,得到例如以下结果: 一.假设装有VC,那就简单了,由于VC带有C的编译器,能够将此路径设置进环境变量. Windows系统下编译连接源码方法: cl -GX test.c -

调用cmd命令行命令(借鉴)

留待以后观看 ---------------------------------------------------------------------------- public class IP_MAC_TypeHelper { /** * 控制台执行arp -a命令 * * @return * */ public static InputStream getInputStream() { Runtime rt = Runtime.getRuntime(); InputStream in =

MySQL命令行工具

shell> mysql --user=user_name --password=your_password db_name shell> mysql --help shell> mysql -? 选项 --protocol={TCP | SOCKET | PIPE | MEMORY} mysql 命令 有些命令mysql可以自己解释.要查看这些命令,在mysql>提示下输入help或\h 默认mysql>可以重新配置,怎么配置有哪几种方法? 1. 使用环境变量 shell&