# Not able to create postgresql user on Ubuntu20

**URL:** <https://forum.ansible.com/t/not-able-to-create-postgresql-user-on-ubuntu20/37874>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [April 12, 2023, 1:14am UTC](https://forum.ansible.com/t/not-able-to-create-postgresql-user-on-ubuntu20/37874 "2023-04-12T01:14:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chihiro\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@Chihiro\_Watanabe](https://forum.ansible.com/u/Chihiro_Watanabe)\
**Post date:** [April 12, 2023, 1:14am UTC](https://forum.ansible.com/t/not-able-to-create-postgresql-user-on-ubuntu20/37874/1 "2023-04-12T01:14:23Z")

</div>

Hi

ansible version: 2.6.7  
python version: 3.8.10  
OS: Ubuntu 20

I want to add postgres user with ansible.  
So I installed required package, psycopg2(python3-psycopg2)

- name: Add role of postgres  
become\_user: postgres  
postgresql\_user:  
name: postgres  
role\_attr\_flags: NOREPLICATION

but Ansible said “the python psycopg2 module is required”  
python-psycopg2 package does not exist in focal repository.  
How can I make ansible use python3-psycopg2?

TASK [postgresql-server : Add role of postgres]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /root/setup/ansible-gerrit/roles/postgresql-server/tasks/db.yml:2  
Tuesday 11 April 2023 17:49:29 +0900 (0:00:02.337) 0:00:23.739 \*\*\*\*\*\*\*\*\*  
 ESTABLISH LOCAL CONNECTION FOR USER: root  
 EXEC /bin/sh -c ‘echo ~root && sleep 0’  
 EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /var/tmp/ansible-tmp-1681202969.7012537-234639475555220`” && echo ansible-tmp-1681202969.7012537-234639475555220=“`echo /var/tmp/ansible-tmp-1681202969.7012537-234639475555220`” ) && sleep 0’  
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/database/postgresql/postgresql\_user.py  
 PUT /root/.ansible/tmp/ansible-local-48574fgls2za0/tmp8hw5m95b TO /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/postgresql\_user.py  
 EXEC /bin/sh -c ‘setfacl -m u:postgres:r-x /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/ /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/postgresql\_user.py && sleep 0’  
 EXEC /bin/sh -c ‘chmod u+x /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/ /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/postgresql\_user.py && sleep 0’  
 EXEC /bin/sh -c ‘chown postgres /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/ /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/postgresql\_user.py && sleep 0’  
 EXEC /bin/sh -c ‘sudo -H -S -n -u postgres /bin/sh -c ‘"’“‘echo BECOME-SUCCESS-egfgzvnxohnublyrrsosdxbthsgsxbqb; /usr/bin/python /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/postgresql\_user.py’”’"’ && sleep 0’  
 EXEC /bin/sh -c ‘rm -f -r /var/tmp/ansible-tmp-1681202969.7012537-234639475555220/ \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
File “/tmp/ansible\_TYsT7h/ansible\_module\_postgresql\_user.py”, line 210, in   
import psycopg2  
fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“conn\_limit”: null,  
“db”: “”,  
“encrypted”: true,  
“expires”: null,  
“fail\_on\_user”: true,  
“login\_host”: “”,  
“login\_password”: “”,  
“login\_unix\_socket”: “”,  
“login\_user”: “postgres”,  
“name”: “postgres”,  
“no\_password\_changes”: false,  
“password”: null,  
“port”: “5432”,  
“priv”: null,  
“role\_attr\_flags”: “NOREPLICATION”,  
“ssl\_mode”: “prefer”,  
“ssl\_rootcert”: null,  
“state”: “present”,  
“user”: “postgres”  
}  
},  
“msg”: “the python psycopg2 module is required”  
}
