Ansible local_action directive

╄→尐↘猪︶ㄣ 提交于 2020-05-25 11:33:04

问题


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

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

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

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


回答1:


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

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 }}

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




回答2:


If you want to provide multiple parameters to the local action it will look something like this

local_action: 
  module: command
  _raw_params: "which nginx"
register: check_nginx
failed_when: no
changed_when: no


来源:https://stackoverflow.com/questions/47391150/ansible-local-action-directive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!