How to fix 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'value' error
Asked Answered
F

1

7

I have defined the nginx_upstreams variable in a different role that in turn uses the geerlingguy.nginx role and I have also specified the "name", "strategy" and the "servers", but when I run this role, ansible throws the error given below as if it cannot access the "name" variable defined for nginx_upstream.

This is the task that throws the error

- name: Create upstream files
  file:
    path: "{{ nginx_vhost_path }}/{{ item.name + '.conf' }}"
    state: touch
  with_items: "{{ nginx_upstreams }}"

This the role to use where the "nginx_upstreams" are defined.

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

This is the ERROR that I get-

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"}
Foremast answered 2/8, 2019 at 21:3 Comment(5)
Do you have the problem when using this instead in the "Create upstream files" task: path: "{{ nginx_vhost_path }}/{{ item.name }}.conf"Britteny
Thanks for your reply. I tried that as well, it didn't work for me. However, I found a workaround to deal with this issue which worked in my case.Foremast
Can you share your workaround?Britteny
@KritikaSharma even i am getting similar problem, can you please share your workaround how you overcome this problem?Archibold
I added the jinja 2 block for creating the upstreams in the vhost file itself, instead of creating a seperate file for it(i.e., I got rid of the "Create upstream files" task). But, I think this workaround is specific to my case.Foremast
T
9

This is caused by a blank variable most likely that is being looped on. Double check your variable is being set correctly.

For example if your task that is failing is this:

- name: Ensure MySQL databases are present.
  mysql_db:
    name: "{{ item.name }}"
    collation: "{{ item.collation | default('utf8_general_ci') }}"
    encoding: "{{ item.encoding | default('utf8') }}"
    state: "{{ item.state | default('present') }}"
  with_items: "{{ mysql_databases }}"

add a debug task:

---
- name: "Debug"
  debug:
    var: mysql_databases
- name: Ensure MySQL databases are present.
  mysql_db:
    name: "{{ item.name }}"
    collation: "{{ item.collation | default('utf8_general_ci') }}"
    encoding: "{{ item.encoding | default('utf8') }}"
    state: "{{ item.state | default('present') }}"
  with_items: "{{ mysql_databases }}"

And then search in that mysql role (atom does easy cross directory searches) for the set_fact for that var (in this case mysql_databases

More than likely you're setting the fact to an empty proxy object

Turnbow answered 4/10, 2019 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.