How can I create an ansible list dynamically with the output of a sql query
<p>I have a playbook in which I want to backup, drop and import the some tables (as a means to update them), don't ask me why I won't just use updates and inserts, it's a complex architecture.</p>

<p>I want to query the postgres database to determine which tables from a specific database to perform the action for those tables. </p>

<p>Like: </p>

<pre><code>- name: Create a list of STATIC TABLES to import later
  command: psql -t -A -d {{ dbname }} -U {{ dbuser }} -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'"
  register: dbtables_data
</code></pre>

<p>And</p>

<pre><code>- name: Backup all tables.
  shell: "pg_dump -U {{ dbuser }} {{ item.name }} -f {{ dbbackup_dir }}/{{ item.name }}.sql"
  with_items: "{{ dbtables_data.results }}"
</code></pre>

<p>This gives me:</p>

<pre><code>fatal: [*.*.*.*] =&gt; with_items expects a list or a set
</code></pre>

<p>And I want to register this output into a list variable so that I can iterate and perform backups, drop and import actions.</p>

<p>Please help</p>