【问题标题】:Running a command in an ansible-playbook from the ansible host using variables from the current ansible process使用当前 ansible 进程中的变量从 ansible 主机运行 ansible-playbook 中的命令
【发布时间】:2017-05-30 14:37:00
【问题描述】:

当我尝试通过远程主机上的 Ansible 运行一个 shell 脚本时,为什么会挂起一个 shell 脚本时遇到了难题,我发现如果我在来自 ansible 主机的 ssh 会话中运行它,它会执行成功。

我现在想将它构建到一个剧本中,如下所示:

- name: Run script
  local_action: shell ssh $TARGET "/home/ansibler/script.sh"

我只需要知道如何从选定/有限的库存中访问运行此剧本的 $TARGET,以便我可以将其连接到 local_action

有没有简单的方法可以访问它?

【问题讨论】:

  • 你想访问这个环境变量TARGET吗?

标签: ansible


【解决方案1】:

试试ansible_host:

- name: Run script
  local_action: 'shell ssh {{ ansible_host }} "/home/ansibler/script.sh"'

【讨论】:

    猜你喜欢
    • 2013-12-09
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2019-11-21
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多