Hello Everyone I have an issue with ansible roles running task with defined vars . . .

Kalesha Gagguturu:
Hello Everyone
I have an issue with ansible roles running task with defined vars. Can some one please help me to resolve it?

I have one of the prod application configured with roles
From roles calling one of the task as

- name: Config app agent
  become: true
  become_user: root
  blockinfile:
    create: true
    state: present
    path: '{{ app_config_path }}'
    owner: '{{ app_config_owner }}'
    group: '{{ app_config_group }}'
    mode: '{{ app_config_mode }}'
    insertbefore: BOF
    marker: "# {mark} Infrastructure config block"
    marker_begin: "Start"
    marker_end: "End"
    block: "{{ app_config_content }}"
  notify: app_agent_restart

And vars are defined as

app_config_content: |
  com.app.plugin.host:
    tags:
      - offering={{ app_tag_offering }}
      - category={{ app_tag_category }}
      - region={{ app_tag_region }}
      - datacenter={{ app_tag_datacenter }}
      - geo={{ app_tag_geo }}
      - availability-zone={{ app_tag_availability_zone }}
      - infrastructure={{ app_tag_infrastructure }} 
      - service={{ app_tag_service }}
  com.app.plugin.generic.hardware:
    enabled: true
    availability-zone: {{ app_tag_availability_zone }}

Can any body help me to fix what went wrong here?

The error message is

FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: com.app.plugin.host:
tags:
- offering={{ app_tag_offering }}
- category={{ app_tag_category }}
- region={{ app_tag_region }}
- datacenter={{ app_tag_datacenter }}
- geo={{ app_tag_geo }}
- availability-zone={{ app_tag_availability_zone }}
- infrastructure={{ app_tag_infrastructure }}
- service={{ app_tag_service }}
com.app.plugin.generic.hardware:
enabled: true
availability-zone: {{ app_tag_availability_zone }}
: 'app_tag_offering' is undefined
The error appears to be in '/home/user/ansible/roles/app/tasks/main.yml': line 58, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
# Configures the properties.
- name: Config app agent\n  ^ here\n"}

Al West:
Hi. Where are you defining the values for all your variables?

Al West:
It says app_tag_offering is undefined

Kalesha Gagguturu:
I am defining in roles/app/vars/main.yml file

Kalesha Gagguturu:
The task is

 blockinfile:
    create: true
    state: present
    path: '{{ app_config_path }}'
    owner: '{{ app_config_owner }}'
    group: '{{ app_config_group }}'
    mode: '{{ app_config_mode }}'
    insertbefore: BOF
    marker: "# {mark} Infrastructure config block"
    marker_begin: "Start"
    marker_end: "End"
    block: "{{ app_config_content }}"
  notify: app_agent_restart

Al West:
I saw the task in your post, show the vars.

Kalesha Gagguturu:
ok

Kalesha Gagguturu:

---
# app agent installation
app_reinstall: false

# app agent configuration
app_agent_url: "******"
app_agent_key: "******"
app_agent_type: "****"
app_agent_location: "*******"
app_config_path: "/opt/app/agent/etc/app/configuration.yaml"
app_config_owner: "root"
app_config_group: "root"
app_config_mode: '0640'
app_config_content: |
  com.app.plugin.host:
    tags:
      - offering={{ app_tag_offering }}
      - category={{ app_tag_category }}
      - region={{ app_tag_region }}
      - datacenter={{ app_tag_datacenter }}
      - geo={{ app_tag_geo }}
      - availability-zone={{ app_tag_availability_zone }}
      - infrastructure={{ app_tag_infrastructure }}
      - service={{ app_tag_service }}
  com.app.plugin.generic.hardware:
    enabled: true
    availability-zone: {{ app_tag_availability_zone }}
...

Kalesha Gagguturu:
This is the content provided for me and I need to fix that to use in that task

Al West:
so it shows that app_tag_offering is not defined

Al West:
is it defined somewhere else?

Kalesha Gagguturu:
No

Al West:
so you see where you have used app_config_group: "root" - that is an assignment

Kalesha Gagguturu:
So that means we need to get all below details and define it in vars right

      - offering={{ app_tag_offering }}
      - category={{ app_tag_category }}
      - region={{ app_tag_region }}
      - datacenter={{ app_tag_datacenter }}
      - geo={{ app_tag_geo }}
      - availability-zone={{ app_tag_availability_zone }}
      - infrastructure={{ app_tag_infrastructure }}
      - service={{ app_tag_service }}

Al West:
but you have no assignment for app_tag_offering

Al West:
for example in your playbook you have fruit = apple and then in your vars you have apple = fruit

Al West:
you need to have something like app_tag_offering: plain

Kalesha Gagguturu:
So I need to have some value in vars file as
app_tag_offering=*****

Right

Al West:
not equals - use colon :

Kalesha Gagguturu:
Ya