ansible的delegate_to、connection、和local_action
由于工作需要,经常需要把目标节点获得的信息写入执行节点文件日志。
所以经常用到delegate_to和connection,而local_action写法难看,基本不用。
delegate_to和connection最后达到的目标是一致的,
就是把目标服务器上的{{ }}大括号标记的变量在代理连接的节点(delegate_to: host)上调用。
示例
inventory_file : /etc/ansible/hosts [controller]
192.168.10.3 node-1
192.168.10.4 node-2
... playbook:
---
- name: connection
hosts: controller
vars:
tmplog: /tmp/connection.log
tasks:
- name: create tmplog
shell: test ! -f {{ tmplog }} && touch {{ tmplog }}
failed_when: false
- name: conneciton
shell: echo "connection . {{ inventory_hostname }} $(hostname) ." >> {{ tmplog }}
connection: local
- name: delegate_to
shell: echo "delegate_to . {{ inventory_hostname }} $(hostname) ." >> {{ tmplog }}
delegate_to: localhost
...
inventory_hostname 当前task的host在inventory文件中的hostname, $(hostname)代理host上的hostname
#####
[root@node-1 test_plays]# cat /tmp/connection.log
connection . 192.168.10.3 node-1.domain.tld .
connection . 192.168.10.4 node-1.domain.tld .
delegate_to . 192.168.10.3 node-1.domain.tld .
delegate_to . 192.168.10.4 node-1.domain.tld .
在node-1上执行,node-2的tmplog都是空的
ansible的delegate_to、connection、和local_action的更多相关文章
- 4.ansible的delegate_to
完成发布流程如下 first 修改nginx 配置文件下线 web1-2 使用 delegate_to 将默认hosts指定为 nginx主机 使用remote_user 将用户 锁定为 root s ...
- Ansible 日常使用技巧 - 运维总结
Ansible默认只会创建5个进程并发执行任务,所以一次任务只能同时控制5台机器执行.如果有大量的机器需要控制,例如20台,Ansible执行一个任务时会先在其中5台上执行,执行成功后再执行下一批5台 ...
- 使用ansible kubectl插件连接kubernetes pod以及实现原理
ansible kubectl connection plugin ansible是目前业界非常火热的自动化运维工具.ansible可以通过ssh连接到目标机器上,从而完成指定的命令或者操作. 在ku ...
- ansible 错误记录(1)
基本环境:docker基于centos7 在docker里面安装ansible 不管是在root还是普通用户下执行 ansible all -m ping 都报如下错误: 172.20.1.1 | ...
- 使用Kubespray在ubuntu上自动部署K8s1.9.0集群
Kubespray 是 Kubernetes incubator 中的项目,目标是提供 Production Ready Kubernetes 部署方案,该项目基础是通过 Ansible Playbo ...
- 记录k8s:k8s1.8.4无坑离线安装
安装部署: 1. 使用vagrant 准备3太虚拟机,自己使用Vbox 准备3太也可以. 2. 按照 https://github.com/gjmzj/kubeasz 安装. 3. 使用letsenc ...
- 【Ansible】SSH Error: ssh_exchange_identification: Connection closed by remote host
ansible ssh到目标机器 时好时坏,报错: SSH Error: ssh_exchange_identification: Connection closed by remote host ...
- ansible 任务委派 delegate_to
ansible 任务委派功能delegate_to run_noce: true 在一个主机上面只执行一次一个任务. ,如果没有这个参数的话,每个playbook中的组的主机都会执行一次. 我们有的 ...
- Ansible安装部署以及常用模块详解
一. Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...
随机推荐
- AtCoder Beginner Contest 122 D - We Like AGC(DP)
题目链接 思路自西瓜and大佬博客:https://www.cnblogs.com/henry-1202/p/10590327.html#_label3 数据范围小 可直接dp f[i][j][a][ ...
- [curl]convert curl to python Ruby
https://curl.trillworks.com/
- nuxt.js实战之移动端rem
nuxt.js的项目由于是服务端渲染,通过js动态调整不同尺寸设备的根字体这种rem方案存在一种缺陷.由于设置字体的代码不能做服务端渲染,导致服务端返回的代码一开始没有相应的跟字体,直到与前端代码进行 ...
- apache http跳转到https代码
<VirtualHost *:> ServerAdmin webmasterexample.com DocumentRoot "/mnt/www/" ServerNam ...
- python去除html标签的几种方法
import re from bs4 import BeautifulSoup from lxml import etree html = '<p>你好</p><br/& ...
- Error creating bean with name
最近在学一个东西,要使用SSM新建一个案例,是这样滴,我有如下 DeptDAO DeptService DeptServiceImpl DeptController Dept Mybatis 首先,我 ...
- SpringBoot系列: Spring支持的异常处理方式
===================================视图函数返回 status code 的方式===================================Spring 有 ...
- [再寄小读者之数学篇](2014-06-20 求极限---Jordan 不等式的应用)
证明: 当 $\lm<1$ 时, $\dps{\lim_{R\to+\infty} R^\lm\int_0^{\pi/2} e^{-R\sin\tt}\rd \tt=0}$. 证明: 由 $$\ ...
- [物理学与PDEs]第1章习题11 各向同性导体中电荷分布的指数衰减
在各向同性的导体中, Ohm 定律具有如下形式: $$\bex {\bf j}=\sigma {\bf E}, \eex$$ 其中 $\sigma$ 称为电导率. 试证在真空中导体的连续性方程为 $$ ...
- babel
一款可以将 ES6 代码转换为 ES5 代码的转译器. 官网:http://babeljs.io/ 中文:https://www.babeljs.cn/