docker extra_host参数需要主机名的字典值,我该如何使用一个variables?

在ansible playbook docker参数中,extra_host需要两部分主机:ip_address。 我试图通过作为variables的主机和ipaddress。 他们来自迅速的变数。 我的hosts文件中的最终结果是: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}}" 

我是新手,任何帮助将不胜感激。

在任务之前用set_fact server_host_ip字典:

 - set_fact: server_host_ip: "{'{{host_name}}':'{{host_ip}}'}" 

{{server_host_ip}}模块中使用{{server_host_ip}}