我的烦人剧本的任务之一如下,该剧本假设要调出EC2实例:
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上打印或创建名称为的文件夹
库存中定义的主机名存储在变量中inventory_hostname
。
因此,要打印出主机名,您需要执行以下操作:
- debug: var=inventory_hostname
要创建目录:
- file:
path: "/tmp/{{ inventory_hostname }}"
state: directory
如果要通过“在Ansible上”来表示要在Ansible控件主机上创建目录,则需要委派任务:
- file:
path: "/tmp/{{ inventory_hostname }}"
state: directory
delegate_to: localhost
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句