Syntax Error with postgresql_query module

428 views
Skip to first unread message

magn...@gmail.com

unread,
May 3, 2019, 3:52:58 PM5/3/19
to Ansible Project
Hi, I have to create and populate a DB with Ansible.
I successfully create the db, but when I add the postgresql_query I got syntax error. 
I also tried to add the code from documentation (here) but it get the same.

The error is:
The offending line appears to be:

      - name: Run queries from SQL script
        ^ here


I put here the playbook, I really have any idea what it could be. Is it a bug?

  - hosts: vm_database
    become: yes
    vars:
     #usate per il lancio senza Cloudify
        an_db_name: db_webserver
        #an_db_user: webserver
        #an_db_password: webserver
    tasks:
      - name: PostgreSQL  installation...
        become_user: root
        package:
            name: "{{ item }}"
            state: present
        loop:
            - postgresql
            #- postgresql-contrib
            #- libpq-dev
            - python-psycopg2

      - name: Check Cluster dir is empty..
        register: foundFiles
        find:
            paths: /var/lib/postgres/data
            patterns: '*.*'

      - name:  Launching initdb ...
        when: foundFiles.matched == 0
        become_user: postgres
        become_flags: -i
        shell: initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'

      - name: Set postgresql.conf to allow remote connection...
        become_user: root
        lineinfile:
            path: /var/lib/postgres/data/postgresql.conf
            regexp: "^#listen_addresses = 'localhost'"
            line: "listen_addresses = '*' "

      - name: Set pg_hba.conf to allow remote connection...
        become_user: root
        lineinfile:
            path: /var/lib/postgres/data/pg_hba.conf
            regexp: 'host.*all.*all.*0.0.0.0/0.*md5'  #da sistemare, non funziona
            firstmatch: yes
            insertafter: '^# IPv4 local connections:*'
            line: "host\tall\t\tall\t\t0.0.0.0/0\t\tmd5"    #controllare -> bazooka

      - name: Service launch..
        become_user: root
        service:
            name: postgresql
            state: started
            enabled: yes

      - name:DB creation..
        become_user: postgres
        postgresql_db:
            name: "{{ an_db_name }}"
            encoding: UTF-8
            lc_collate: it_IT.UTF-8
            lc_ctype: it_IT.UTF-8
            template: template0
            state: present

      - name: User creation..
        become_user: postgres
        postgresql_user:
            db: "{{ an_db_name }}"
            name: "{{ an_db_user }}"
            password: "{{ an_db_password }}"
            priv: ALL
            role_attr_flags: LOGIN,CREATEDB
            state: present
###EVERYTHING FINE TILL HERE####
      - name: Run queries from SQL script...
        become_user: postgres
        postgresql_query:
            db: "{{ an_db_name }}"
            path_to_script: Resource/00-create.sql
            positional_args: 1

Jonathan Lozada De La Matta

unread,
May 3, 2019, 4:04:40 PM5/3/19
to ansible...@googlegroups.com
can you run it with -vvv ?

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5d7c4e35-e113-4e0d-a929-905ea73b8d74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Jonathan Cha'gara Lozada De La Matta

He / Him / His

Automation Practice

Senior Automation Consultant & Automation CoP Manager

Red Hat


 

magn...@gmail.com

unread,
May 4, 2019, 5:16:42 AM5/4/19
to Ansible Project
The output is:

ansible-playbook 2.7.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/andrea/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.7.3 (default, Mar 26 2019, 21:43:19) [GCC 8.2.1 20181127]
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
Parsed /etc/ansible/hosts inventory source with ini plugin
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/home/andrea/Documenti/Tirocinio/Cloudify/BluePrint/Database/database_create.yml': line 76, column 9, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

      - name: Run queries from SQL script
        ^ here
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

magn...@gmail.com

unread,
May 4, 2019, 5:31:38 AM5/4/19
to Ansible Project
SOLUTION FOUND
Sorry I'm very stupid and I shouldn't work at night.
The problem is that postgresql_query is new in version 2.8 in development, and I have 2.7.10
Thank you for your time
Reply all
Reply to author
Forward
0 new messages