我有以下任务:
- name: copy server.xml
  template: src=server.xml dest=/var/containers/{{ item.key }}/conf
  with_dict: containers
我还在group_vars中添加了容器字典
containers:
  frontend:
    http_port: 8080
  backend:
    http_port: 8081
最后,这是server.xml的相关代码段
<Connector port="{{ http_port }}" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
我想要发生的是在模板模块中使用相关的http_port.但相反,我得到并错误:
致命:[localhost] => {'msg':"AnsibleUndefinedVariable:一个或多个未定义的变量:'http_port'未定义",'失败':真}
这可能吗?如何利用项目的值进行变量替换?
我正在尝试创建具有与其with_items值匹配的值的文件.
我有一个像这样的var列表:
 sites:
   - domain: google.com
     cname: blue
   - domain: facebook.com
     cname: green
   - domain: twitter.com
     cname: red
我为此任务中的列表中的每个对象创建单个文件:
- name: Create files
  template:
    src: file.conf
    dest: "/etc/nginx/conf.d/{{item.cname}}.conf"
  with_items: "{{sites}}"
这些都很有效.我需要什么,有我的模板文件为它创建一个名为blue.conf并且有google.com它只是.
我尝试了很多变化.我最接近的是:
   server {
        listen 80;
        listen [::]:80;
      {% for item in sites %}
        server_name  {{item.cname}}.es.nodesource.io;
        location / {
          proxy_pass {{item.domain}};
        }
      {% endfor %}
    }
这将创建单个文件,但每个文件都包含所有域和名称.