Ansible local_action 指令 [英] Ansible local_action directive

查看:46
本文介绍了Ansible local_action 指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ansible 的新手,有一个简单的问题来帮助我理解 local_action 指令.

I'm quite new to Ansible and have a simple question for my understanding of local_action directive.

这是否意味着该命令在本地完全执行?假设您有这样的事情:

Would that mean that the command is fully executed locally? Let's say you have something like this:

local_action: command which nginx
register: check_nginx
failed_when: no
changed_when: no

然后你有另一个块用类似的东西寻找 nginx 的存在:

Then you have another block looking for nginx's existence with something like that:

- fail: msg="nginx unavailable"
  when: check_nginx.rc == 1

这是否意味着如果 nginx 没有安装在本地,playbook 会失败,或者如果没有远程安装,它会失败吗?

Does that mean that playbook will fail in case nginx is not installed locally or will it fail if is not installed remotely ?

推荐答案

是的,local_action 是执行 delegate_to: localhost 的另一种方式.

Yes, local_action is an alternative way of doing delegate_to: localhost.

这些操作将在本地机器(Ansible 控制主机)上执行,但在变量方面仍处于远程主机的上下文中.所以你可以这样:

These actions will be executed on local machine (Ansible control host), but still being in context of remote host in terms of variables. So you can something like this:

local_action: command ping -c 1 {{ inventory_hostname }}

这将 ping 游戏中的每个主机,但 ping 将从 Ansible 控制主机启动.

which will ping every host in your play, but ping will be initiated from Ansible control host.

这篇关于Ansible local_action 指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆