Warning: is_dir(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/data/web/virtuals/98151/virtual) in /data/web/virtuals/98151/virtual/www/subdom/postgresql/wp-content/plugins/wp-simple-firewall/src/lib/vendor/fernleafsystems/wordpress-services/src/Core/Fs.php on line 465

Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/98151/virtual/www/subdom/postgresql/wp-content/plugins/wp-simple-firewall/src/lib/vendor/fernleafsystems/wordpress-services/src/Core/Fs.php:465) in /data/web/virtuals/98151/virtual/www/subdom/postgresql/wp-content/plugins/disable-xml-rpc-pingback/disable-xml-rpc-pingback.php on line 51
Ansible - simple playbook for installing PostgreSQL on Ubuntu/ Debian - PostgreSQL Candies
# install postgresql on remote instance
# 
# run:
# ansible-playbook "yourplaybookname.yaml" -i ./hosts -e "postgresql_version=..." -e "myinstance=..."
#

- name: install postgresql on Ubuntu or Debian
  hosts: "{{myinstance}}"
  become: yes
  become_method: sudo
  gather_facts: yes

  tasks:
  - debug: msg="play_hosts={{play_hosts}}"
  - debug: msg="ansible_distribution={{ansible_distribution}}"

  - name: postgresql key
    apt_key:
      url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
      state: present
    become: true
    
  - name: create variable
    command: bash -c "echo \"deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main\" "
    register: repo_line

  - debug: 
      msg: "{{ repo_line.stdout }}"
      
  - name: add postgresql repo 
    apt_repository:
      repo: "{{ repo_line.stdout }}"
      state: present
    become: true

  - name: install postgresql
    apt:
      name: "postgresql-{{postgresql_version}}"
      state: present
      update_cache: yes
    become: true