docker extra_host 参数需要主机名的字典值,如何使用变量? [英] docker extra_host parameter expects a dictionary value for hostname, how can I use a variable?

查看:48
本文介绍了docker extra_host 参数需要主机名的字典值,如何使用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ansible playbook docker 参数 extra_host 包含两部分主机:ip_address.我试图将主机和 ipaddress 作为变量传递.它们来自提示变量.我的主机文件中的最终结果是:1.2.3.4 {{server_hostname}}.代码如下:

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}}"

我是 ansible playbook 的新手,任何帮助将不胜感激.

I am new to ansible playbook any help would be greatly appreciated.

推荐答案

在你的任务之前使用 set_fact 制作 server_host_ip dict:

Make server_host_ip dict with set_fact before your task:

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

并在 docker 模块中使用 {{server_host_ip}}.

And use {{server_host_ip}} in the docker module.

这篇关于docker extra_host 参数需要主机名的字典值,如何使用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆