Jinja2 filters return strings, not arrays, so use a "when" statement to
skip lines you do not want to hit:
tasks:
- name: dump data into csv
sudo: yes
sudo_user: postgres
command: psql -d cmdbuild -c "COPY \"{{ item }}\" to '/tmp/{{ item
}}.csv' $
when: item not in supertables
with_items: almatables.stdout_lines
This should do what you want.
On Wed, May 28, 2014 at 2:41 AM, <[email protected]> wrote:
> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/62d0e894-4f00-4900-8cf1-c47fbd0bdbe2%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/62d0e894-4f00-4900-8cf1-c47fbd0bdbe2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAMFyvFgTmpTwpHr7mFrENAWKBXkbqLbNVOFA1qDGQMh%2BG%2BV0mQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.