docker extra_host parameter expects a dictionary value for hostname, how can I use a variable?

Deadly 提交于 2019-12-02 17:12:51

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!