【发布时间】:2019-08-02 21:03:38
【问题描述】:
我已经在另一个角色中定义了 nginx_upstreams 变量,该角色又使用了 geerlingguy.nginx 角色,我还指定了“名称”、“策略”和“服务器”,但是当我运行这个角色时,ansible 抛出下面给出的错误好像它无法访问为 nginx_upstream 定义的“名称”变量。
这是引发错误的任务
- name: Create upstream files
file:
path: "{{ nginx_vhost_path }}/{{ item.name + '.conf' }}"
state: touch
with_items: "{{ nginx_upstreams }}"
这是定义“nginx_upstreams”时使用的角色。
- name: "Configure specific nginx service for concert to connect on remote host"
include_role:
name: geerlingguy.nginx
vars:
#for configuration specific to each server
nginx_upstreams:
- name: SOME_UPSTREAM_NAME
strategy: SOME_STRATEGY
servers: "{{ SOME_SERVER }}"
这是我得到的错误 -
fatal: [IP]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'value'\n\nThe error appears to be in '/etc/ansible/roles/geerlingguy.nginx/tasks/vhosts.yml': line 29, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create upstream files\n ^ here\n"}
【问题讨论】:
-
在“创建上游文件”任务中改用这个是否有问题:
path: "{{ nginx_vhost_path }}/{{ item.name }}.conf" -
感谢您的回复。我也试过了,它对我不起作用。但是,我找到了解决此问题的解决方法。
-
你能分享你的解决方法吗?
-
@KritikaSharma 即使我遇到了类似的问题,你能分享一下你是如何克服这个问题的吗?
-
我添加了 jinja 2 块用于在 vhost 文件本身中创建上游,而不是为其创建单独的文件(即,我摆脱了“创建上游文件”任务)。但是,我认为这种解决方法是针对我的情况的。
标签: ansible ansible-2.x ansible-inventory ansible-template