Reputation: 1059
I have a role that runs some SQL queries and I create a dictionary with the results. I've removed some logic in hopes to better understand. Even when setting static key and value I'm still getting AnsibleUnsafeText
.
ROLE
---
- name: Get Event Table Record Count
command: <sql_command>
register: record_count
- name: Get Event Tables oldest Record
command: <sql_command>
register: oldest_record
- name: Mapping Results
set_fact:
results: "{{ results|default({})|combine({'count': 5}) }}"
PLAYBOOK
---
- name: Clean Tables.
hosts: all
gather_facts: true
become: true
vars:
event_tables:
- table1
- table2
- table3
tasks:
- name: Get Event Table Count and Oldest Event Date
include_role:
name: get_count_and_latest_record
with_items: "{{ event_tables }}"
vars:
- table: "{{ item }}"
- debug: msg="{{ item | type_debug }}"
with_items: "{{ event_tables }}"
I don't understand what specific text is unsafe?
"msg": "AnsibleUnsafeText",
Upvotes: 1
Views: 5401
Reputation: 12122
Since you are registering the result of a command in a variable, Ansible can't know what will be the content which becomes delivered. Therefore the registered Text
output is marked as Unsafe
.
You can find further background information in Unsafe or raw strings.
When handling values returned by ... Ansible uses a data type called unsafe to block templating. Marking data as unsafe prevents malicious users from abusing Jinja2 templates to execute arbitrary code on target machines. The Ansible implementation ensures that unsafe values are never templated.
Further Information
An introduction to Ansible facts
Ansible Unsafe Text: This type of variable doesn't have any subpart and stores the data directly
Depending on what is stored within your AnsibleUnsafeText
you would need to do a type casting for further processing.
Further Q&A
Upvotes: 2