获取主机名Ansible

时间:2018-04-03 11:22:52

标签: ansible ansible-2.x hosts

我想在Ansible剧本中做一件非常简单的事情。

ansible appserver -m setup -a 'filter=ansible_hostname' | head -n1 | awk '{print $1;}'

此命令的输出将返回您当前正在运行脚本的主机名。作为一项任务,有没有办法在剧本中做到这一点?

1 个答案:

答案 0 :(得分:0)

发现:如果gather_facts设置为true,则可以使用{{ansible_hostname}}。