Ansible安装配置和基本使用 。小编来告诉你更多相关信息 。
Ansible安装配置和基本使用使用逻辑与
在websrvs组并且在dbsrvs组中的主机 。
[root@ansible-srv1 ansible-example]# ansible \"websrvs:&dbsrvs\" -m ping10.10.108.30 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}
使用逻辑非
在websrvs组,但不在dbsrvs组中的主机.注意:此处只能是单引号 。
[root@ansible-srv1 ansible-example]# ansible \'websrvs:!dbsrvs\' -m ping10.10.108.33 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}10.10.108.31 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}10.10.108.32 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}
使用正则表达式
[root@ansible-srv1 ansible-example]# ansible \"websrvs:&dbsrvs\" -m ping10.10.108.30 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}[root@ansible-srv1 ansible-example]# ansible \"~(web|db)srvs\" -m ping10.10.108.30 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}10.10.108.33 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}10.10.108.31 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}10.10.108.32 | SUCCESS => {\"ansible_facts\": {\"discovered_interpreter_python\": \"/usr/bin/python\"},\"changed\": false,\"ping\": \"pong\"}
3.2.2 ansible执行命令过程
- 加载自己的配置文件默认
/etc/ansible/ansible.cfg
,如果指定了你自定义的清单文件,则从自己的清单文件中查找被管理主机 - 加载自己对应的模块文件,如:
command
- 通过ansible将模块或命令生成对应的临时py文件,并将该文件传输至远程服务器的对应执行用户
$HOME/.ansible/tmp/ansible-tmp-数字/XXX.PY
文件 - 给文件+x执行
- 执行并返回结果
- 删除临时py文件,退出
-v
或者-vvv
列出详细的执行过程(可以多加几个v参数) 。[root@ansible-srv1 ansible-example]# ansible \"~(web|db)servers\" -vvv -m ping > ansible.log[root@ansible-srv1 ansible-example]# grep \"chmod\" ansible.log
3.2.3 ansible执行后颜色描述默认情况下是以下三种颜色:Ansible安装配置和基本使用 。小编来告诉你更多相关信息 。
Ansible安装配置和基本使用
- 绿色:表示成功
- 黄色:修改了远程文件后并执行成功
- 红色:表示执行失败
[root@ansible-srv1 ansible-example]# vim /etc/ansible/ansible.cfg[colors]#highlight = white#verbose = blue#warn = bright purple#error = red#debug = dark gray#deprecate = purple#skip = cyan#unreachable = red#ok = green#changed = yellow#diff_add = green#diff_remove = red#diff_lines = cyan
3.2.4 Ansible-playbook示例[root@ansible-srv1 ansible-example]# cat echo-demo.yml---- hosts: dbsrvsremote_user: roottasks:- name: echo demoshell: echo \"第一个 ansible-playbook 示例\" [root@ansible-srv1 ansible-example]# ansible-playbook echo-demo.yml
解释:这里指定主机组为:dbsrvs
,指定远程用户为root
,使用shell
模块执行了一个echo命令 。3.2.5 ansible-vault该工具用于对yaml文件进行加解密,格式如下:
ansible-vault [create|decrypt|edit|encrypt|rekey|view]如:ansible-vault encrypt echo-demo.yml# 加密ansible-vault view echo-demo.yml# 查看ansible-vault decrypt echo-demo.yml# 解密ansible-vault edit echo-demo.yml# 编辑加密文件ansible-vault create echo-demo.yml# 创建新文件
Ansible是一个简单高效且很强大的工具,它的功能远不止于此 。而那些不常用的命令工具,本文也暂不介绍,学习了不用也是在浪费自己的时间 。如果有兴趣的话可以去官网或者其他站点查阅资料自行了解 。【Ansible安装配置和基本使用】以上就是带来的Ansible安装配置和基本使用的全部内容,您了解了吗?
- Ansible简介及离线安装步骤 Ansible简介与离线安装
- 功能优点详细介绍! 什么是ansible
- 刺客信条启示录配置高吗 配置要求低的游戏推荐
- RedHatLinux系统下yum源配置的详细指南
- ubuntu安装chrome浏览器的方法 ubuntu怎么安装chrome
- 3dmax插件怎么安装插件 3dmax一键生成墙体插件安装
- 驱动程序怎么卸载重装 电脑安装的驱动流程
- HP打印机怎么安装驱动程序 惠普1020打印机驱动下载
- 无线路由器设置方法步骤 wifi路由器怎么安装
- OSPF被动接口配置方法 如何配置OSPF被动接口