Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql install with ansible

---
- name: Install and set up Postgres 14 in Ubuntu 20.04
  hosts: ubuntusrv
  become: yes
  gather_facts: False
  vars:
    postgres_root_user: root
    postgres_root_pass: GQt5MTyVPuf9vsVWoWDT9YCn
    allow_world_readable_tmpfiles: true
  tasks:
    - name: Update apt repo and cache on all Ubuntu boxes
      apt:
        update_cache: yes
        force_apt_get: yes
        cache_valid_time: 3600

    - name: Upgrade all packages on servers
      apt:
        upgrade: dist
        force_apt_get: yes

    - name: Install required packages
      apt:
        name:
          - wget
          - python3-psycopg2
          - acl
        state: latest

    - name: Set up Postgres 14 repo
      shell: |
        echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
        wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
      args:
        warn: no

    - name: Install postgresql
      apt:
        name: postgresql-14
        update_cache: yes
      notify:
        - Enable Postgresql

    - name: Ensure PostgreSQL is listening on *
      lineinfile:
        dest: /etc/postgresql/14/main/postgresql.conf
        regexp: '^listen_addressess*='
        line: "listen_addresses='*'"
        state: present
      notify: Restart Postgresql

    - name: Add new configuration to "pg_hba.conf"
      blockinfile:
        dest: /etc/postgresql/14/main/pg_hba.conf
        block: |
          host    all             all             0.0.0.0/0                md5
          host    all             all             ::/0                     md5
      notify: Restart Postgresql

    - name: Change peer identification to trust
      shell: /bin/sed -i '/^local/s/peer/trust/' /etc/postgresql/14/main/pg_hba.conf
      args:
        warn: no
      notify: Restart Postgresql

    - name: Create a Superuser PostgreSQL database user
      become: yes
      become_user: postgres
      postgresql_user:
        name: '{{ postgres_root_user }}'
        password: '{{ postgres_root_pass }}'
        role_attr_flags: CREATEDB,SUPERUSER,CREATEROLE
        encrypted: yes
        state: present

  handlers:
    - name: Restart Postgresql
      systemd:
        name: postgresql
        state: restarted

    - name: Start Postgresql
      systemd:
        name: postgresql
        state: started

    - name: Stop Postgresql
      systemd:
        name: postgresql
        state: stopped

    - name: Enable Postgresql
      systemd:
        name: postgresql
        enabled: yes
Comment

PREVIOUS NEXT
Code Example
Sql :: sql query to delete duplicate records 
Sql :: oracle job session 
Sql :: sql change primary key to composite key 
Sql :: sqlstate[hy000] [2006] mysql server has gone away laravel 
Sql :: where name ends in SQL 
Sql :: cannot connect to mysql server 10060 
Sql :: sql reverse 
Sql :: soql last year 
Sql :: Deleting data from tables 
Sql :: Insert Multiple Rows at Once in SQL 
Sql :: sorting desc in sql 
Sql :: sql create table as 
Sql :: ruby sqlite 
Sql :: what is auto increment in sql 
Sql :: SQL Using Prepared Statements 
Sql :: sqlite csv 
Sql :: how to use sqlcommand 
Sql :: postgres add foreign key to existing table 
Sql :: oracle exchange subpartition 
Sql :: break too long line yaml 
Sql :: sqlite dropping multiple tables 
Sql :: mysql create index lost connection 
Sql :: sql shell psql cannot enter password 
Sql :: sqldf change user 
Sql :: sql convert to linq online 
Sql :: sql multiple column 
Sql :: how to convert exponential expression to n decimal float in postgresql 
Sql :: postgresql < ALL very slow 
Sql :: Having trouble running COUNT in my INSERT INTO statement 
Sql :: ring MySQL get the result data without columns names 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =