获取主机名 Ansible

Get the host names Ansible

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

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

此命令的输出返回您当前运行脚本所针对的主机名。有什么办法可以在剧本中作为一项任务来做到这一点?

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