Trying to figure out theory filters, but no luck yet. I'm pulling a list of available tables from postgres and exclude the tables contained in the list supertables.
Am i using this functionality in the correct way? Or do i need to put it in a variable first? If so, how do i do that?
I'm using ansible 1.4.4+dfsg-1~ubuntu12.04.1
My playbook:
---
- hosts: pdetest2
vars:
supertables:
- ALMA_asset
- ALMA_computer
tasks:
- name: get list of ALMA tables
sudo: yes
sudo_user: postgres
command: psql cmdbuild -t -c "select tablename from pg_catalog.pg_tables where tablename like '%ALMA_%' ORDER BY tablename;"
register: almatables
- name: debug
debug: var=supertables
- name: debug
debug: var=almatables.stdout_lines
- name: dump data into csv
sudo: yes
sudo_user: postgres
command: psql -d cmdbuild -c "COPY \"{{ item }}\" to '/tmp/{{ item }}.csv' CSV;"
with_items: almatables.stdout_lines | difference(supertables)Ansible fails with:
TASK: [debug] *****************************************************************
ok: [pdetest2] => {
"supertables": [
"ALMA_asset",
"ALMA_computer"
]
}
TASK: [debug] *****************************************************************
ok: [pdetest2] => {
"almatables.stdout_lines": [
" ALMA_Asset",
" ALMA_Building",
" ALMA_Building_history",
" ALMA_Cabinet",
" ALMA_Cabinet_history",
" ALMA_Certificate",
<snip>
" Map_ALMA_Software_InstalledSoftware_history"
]
}
TASK: [dump data into csv] ****************************************************
fatal: [pdetest2] => with_items expects a list
FATAL: all hosts have already failed -- aborting
So i tried to dumb it down:
- hosts: pdetest2
vars:
almatables:
- ALMA_asset
- ALMA_VirtualComputer
supertables:
- ALMA_asset
- ALMA_computer
tasks:
- name: dump data into csv
sudo: yes
sudo_user: postgres
command: psql -d cmdbuild -c "COPY \"{{ item }}\" to '/tmp/{{ item }}.csv' $
with_items: almatables | difference(supertables)
Fails with the same error:
TASK: [dump data into csv] ****************************************************
fatal: [pdetest2] => with_items expects a list