2016-03-08 80 views
1

我的一个ansible剧本的任务是低于,而这剧本假设带来了一个EC2实例:打印出ansible主机名

TASK: [Demo] ****************************************************************** 
changed: [ec2-52-24-222-200.us-west-2.compute.amazonaws.com] => (item=ec2.instances) 

我怎样才能打印出来,或创建一个文件夹名称ec2-52-24-222-200.us-west-2.compute.amazonaws.com Ansible

+0

什么你的剧本呢?你可以编辑你的问题,包括它? – ydaetskcoR

+0

本手册假设在AWS上启动一个ec2实例。我在问题 – Alexander

回答

3

您的清单中定义的主机名存储在变量​​中。

所以要打印出来的主机名,你会怎么做:

- debug: var=inventory_hostname 

要创建一个目录:

- file: 
    path: "/tmp/{{ inventory_hostname }}" 
    state: directory 

如果你叫“上Ansible”要创建目录在Ansible控制主机上,您需要委托任务:

- file: 
    path: "/tmp/{{ inventory_hostname }}" 
    state: directory 
    delegate_to: localhost 
+0

中提到谢谢,它解决了我的问题 – Alexander