在Ansible Playbook中,泊坞窗参数extra_host包含两部分主机:ip_address。我正在尝试将主机和ipaddress作为变量传递。它们来自即时变量。我的主机文件的最终结果是:1.2.3.4 {{server_hostname}}。这是代码:
vars_prompt: - name: "server_ip" prompt: "Please enter the server IP address" private: no - name: "server_hostname" prompt: "Please enter the server hostname" private: no tasks: - name: Install Tomcat docker: image: tomcat:8.0 pull: missing name: tomcat state: restarted ports: - "8080:8080" - "443:443" extra_hosts: "{{server_hostname}}": "{{server_ip}}"
我不熟悉ansible剧本,对您的帮助将不胜感激。
让server_host_ip字典与set_fact您的任务之前:
server_host_ip
set_fact
- set_fact: server_host_ip: "{'{{host_name}}':'{{host_ip}}'}"
并{{server_host_ip}}在docker模块中使用。
{{server_host_ip}}
docker