Playboox only runs the second time

Hi friends in Ansible
I have a playbook that sets up a PostgreSQL environment.
One of the tasks sets up a db user.
This task always fails the first time. The error is, that psycopg2 could not be loaded.
If I run the playbook a second time, it works without a glitch.

A clumsy solution I found is to split the playbook into two parts. Running them in sequence work without a problem.

Could anybody of you give me a hint on how to find a solution for this?

thanks
Robert

here is the failing task:

  • name: PostgreSQL - Add the config db Odoo user
    become: true
    become_user: postgres
    postgresql_user:
    name: ‘{{ odoo_config_db_user }}’
    password: ‘{{ odoo_config_db_passwd_crypt }}’
    encrypted: yes
    role_attr_flags: ‘{{ odoo_postgresql_user_role_attr }}’
    ignore_errors: yes

Hi Robert

This doesn’t make a whole lot of sense why this would fail and then work. Definitely being applied to the SAME host on each run?
I suggest you post your whole playbook(s) here as there’s something else going on outside the mentioned failing task I suspect.

As a good measure I would also include something like:

- name: Make sure psycopg2 is installed
  pip:
    name: psycopg2
    state: present
before you need it to ensure that base is covered as well.
Phil.