So, I’m trying to built a task list for backing up our primary DB server. The issue is that ONE database has a hyphenated name (no, I’m not the one that did something that stupid). Here’s the task that bombs:
-
name: backup mysql
vars:
exclude_db: -
“information_schema”
-
“performance_schema”
-
“mysql”
-
“test”
-
“sat_master”
-
“
google-provisioning
”
shell: 'mysql -NBA -e “show databases;” ’
register: dblist -
name: backup databases
mysql_db:
state: dump
name: “{{ item }}”
target: “/backups/{{ ansible_month }}/{{ ansible_day }}/{{ item }}_bu.bz2”
login_user: root
#login_password: “{{ vault_root_passwd }}”
with_items: “{{ dblist.stdout_lines | difference(exclude_db) }}”
And here’s the error message:
Unable to look up a name or access an attribute in template string ({{ dblist.stdout_lines | difference(exclude_db) }}).
Make sure your variable name does not contain invalid characters like ‘-’: argument of type ‘StrictUndefined’ is not iterable
I can build shell commands for this if I have to, but is there a way to make ansible behave with this one DB? BTW, I’ve added it to the vars it’s ‘google-provisioning’. I’ve tried the backticks as per normal mysql methods, but that doesn’t seem to help. I’ve also tried escape it via \ but nothing has worked. I’d really like to strangle the cretin that did this, but is there any way to make this work without hand crafting individual backup tasks?