In ansible playbook docker parameter extra_host takes two parts host: ip_address. I am trying to pass the host and ipaddress in as variables. They are from prompt vars. The end result in my hosts file is: 1.2.3.4 {{server_hostname}}. Here is the code:
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}}"
I am new to ansible playbook any help would be greatly appreciated.
Make server_host_ip
dict with set_fact
before your task:
- set_fact:
server_host_ip: "{'{{host_name}}':'{{host_ip}}'}"
And use {{server_host_ip}}
in the docker
module.
来源:https://stackoverflow.com/questions/37729868/docker-extra-host-parameter-expects-a-dictionary-value-for-hostname-how-can-i-u