I have the following regex in my playbook:
name: get business ID
set_fact:
my_var: “{{ inventory_hostname | regex_findall(‘.+?(?=-).+?(?=-).+?(?=-).+?(?=-)+’) }}”
the debug returns the right value:
ok: [DE-LEI-GRO-GROLE-F001-FW01-MDF] => {
“my_var”: [
“DE-LEI-GRO-GROLE”
when using create directory
name: create directory
file:
path: /home/vinn/devicebackups/{{ my_var }}
state: directory
its creates the directory adding [’ ’]
“path”: “/home/vinn/devicebackups/[''DE-LEI-GRO-GROLE’]”,
any idea why??
thanks a lot
vbotka
(Vladimir Botka)
October 20, 2020, 11:54pm
2
I have the following regex in my playbook:
- name: get business ID
set_fact:
my_var: "{{ inventory_hostname |
regex_findall('.+?(?=-).+?(?=-).+?(?=-).+?(?=-)+') }}"
the debug returns the right value:
ok: [DE-LEI-GRO-GROLE-F001-FW01-MDF] => {
"my_var": [
"DE-LEI-GRO-GROLE"
The bracket '[' tells us the variable my_var is a list. It's not
clear how the set_fact above managed to create the list.
when using create directory
- name: create directory
file:
path: /home/vinn/devicebackups/{{ my_var }}
state: directory
its creates the directory adding [' ’]
"path": "/home/vinn/devicebackups/[''DE-LEI-GRO-GROLE’]",
any idea why??
The variable my_var is a list.
vbotka
(Vladimir Botka)
October 21, 2020, 12:04am
3
thanks
could it be that hyphen - are not allowed in the variable string?