initial commit
This commit is contained in:
		
						commit
						1a601efca4
					
				
					 4 changed files with 84 additions and 0 deletions
				
			
		
							
								
								
									
										4
									
								
								ansible-postgresql/roles/postgresql16/handlers/main.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								ansible-postgresql/roles/postgresql16/handlers/main.yml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | |||
| - name: Restart PostgreSQL 16 | ||||
|   systemd: | ||||
|     name: postgresql | ||||
|     state: restarted | ||||
							
								
								
									
										72
									
								
								ansible-postgresql/roles/postgresql16/tasks/main.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								ansible-postgresql/roles/postgresql16/tasks/main.yml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,72 @@ | |||
| - name: Update apt package index | ||||
|   apt: | ||||
|     update_cache: yes | ||||
| 
 | ||||
| - name: Install necessary dependencies | ||||
|   apt: | ||||
|     name: | ||||
|       - wget | ||||
|       - ca-certificates | ||||
|     state: present | ||||
| 
 | ||||
| - name: Add PostgreSQL GPG key | ||||
|   apt_key: | ||||
|     url: https://www.postgresql.org/media/keys/ACCC4CF8.asc | ||||
|     state: present | ||||
| 
 | ||||
| - name: Add PostgreSQL APT repository | ||||
|   apt_repository: | ||||
|     repo: "deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main" | ||||
|     state: present | ||||
|     update_cache: yes | ||||
| 
 | ||||
| - name: Install PostgreSQL 16 and its dependencies | ||||
|   apt: | ||||
|     name: | ||||
|       - postgresql-16 | ||||
|       - postgresql-client-16 | ||||
|       - postgresql-contrib | ||||
|       - python3-psycopg2 | ||||
|     state: present | ||||
| 
 | ||||
| - name: Install python3-psycopg2 | ||||
|   apt: | ||||
|     name: | ||||
|       - python3-psycopg2 | ||||
|     state: present | ||||
| 
 | ||||
| - name: Ensure PostgreSQL is running and enabled on boot | ||||
|   systemd: | ||||
|     name: postgresql | ||||
|     state: started | ||||
|     enabled: yes | ||||
| 
 | ||||
| - name: Copy PostgreSQL configuration | ||||
|   template: | ||||
|     src: postgresql.conf.j2 | ||||
|     dest: /etc/postgresql/16/main/postgresql.conf | ||||
|   notify: | ||||
|     - Restart PostgreSQL 16 | ||||
| 
 | ||||
| - name: Create a database user | ||||
|   become_user: postgres | ||||
|   postgresql_user: | ||||
|     name: testuser | ||||
|     password: testpassword | ||||
|     state: present | ||||
| 
 | ||||
| - name: Create a database | ||||
|   become_user: postgres | ||||
|   postgresql_db: | ||||
|     name: testdb | ||||
|     owner: testuser | ||||
|     state: present | ||||
| 
 | ||||
| - name: Grant privileges to the user on the database | ||||
|   become_user: postgres | ||||
|   postgresql_privs: | ||||
|     database: testdb | ||||
|     roles: testuser | ||||
|     objs: ALL_IN_SCHEMA | ||||
|     privs: "ALL" | ||||
|     state: present | ||||
|  | @ -0,0 +1,3 @@ | |||
| listen_addresses = '*' | ||||
| port = 5432 | ||||
| max_connections = 100 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue