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

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

问题描述

在可粘贴的playbook docker参数中,extra_host需要两部分主机:ip_address。我试图将主机和ipaddress作为变量传递。他们来自提示的vars。我的主机文件的最终结果是: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}}"

我是新的可编辑的手册,任何帮助将不胜感激。

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

推荐答案

Make server_host_ip dict with set_fact 在您的任务之前:

Make server_host_ip dict with set_fact before your task:

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

并使用 {{server_host_i p>} docker 模块中。

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

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