Ansible local_action指令 [英] Ansible local_action directive

查看:1372
本文介绍了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,则剧本会失败,或者如果未远程安装,则剧本会失败吗?

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天全站免登陆