# installing postgresql -- permission problem with initdb

**URL:** <https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886>\
**Category:** Ansible Project\
**Created:** [October 17, 2021, 3:47pm UTC](https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886 "2021-10-17T15:47:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 17, 2021, 3:47pm UTC](https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886/1 "2021-10-17T15:47:20Z")

</div>

I have a task to create an initial postgres databa (initdb) in a playbook installing postgresql from a tar.gz archive on a centos7 target

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 17, 2021, 5:28pm UTC](https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886/2 "2021-10-17T17:28:08Z")

</div>

> I have a task to create an initial postgres databa (initdb) in a playbook installing postgresql from a tar.gz archive on a centos7 target
> 
> ###################################################################
> 
> - name: configure postgres - create database  
> command:/opt/db/postgres/postgresql/src/bin/initdb -D /opt/db/data/postgres/data  
> args:  
> creates: /opt/db/data/postgres/PG\_VERSION"  
> become: yes  
> become\_user: postgres
> 
> ###################################################################
> 
> playbook execution throws the following error at me:
> 
> ###################################################################
> 
> _TASK [configure postgres - create database] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
> _fatal: [vm-0179]: FAILED! =\> changed=false_  
> _cmd: /opt/db/postgres/postgresql/src/bin/initdb -D /opt/db/data/postgres/data_  
> _msg: ‘[Errno 13] Permission denied’_  
> _rc: 13_
> 
> ###################################################################
> 
> I read this as the user running that task (postgres) may not have rw permissions to the parent directory
> 
> however this indicates somethin else
> 
> ###################################################################
> 
> _\> ls -l /opt/db/data/postgres/_  
> _drwxr-x—. 2 postgres postgres 6 14. Okt 10:34 data_

There is a trailing dot, which indicates some SElinux security context. That may prevent your task from completing

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 18, 2021, 10:04am UTC](https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886/3 "2021-10-18T10:04:37Z")

</div>

thx,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 18, 2021, 2:37pm UTC](https://forum.ansible.com/t/installing-postgresql-permission-problem-with-initdb/35886/4 "2021-10-18T14:37:09Z")

</div>

This proves there is some permissions issue.  
So best to solve that and make initdb work manually, and then ansiblize the process.
