Skip to content

Instantly share code, notes, and snippets.

@gravcat
Last active August 13, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravcat/0bebfe665baf3ed3b33ef5de681c237b to your computer and use it in GitHub Desktop.
Save gravcat/0bebfe665baf3ed3b33ef5de681c237b to your computer and use it in GitHub Desktop.
check for an existing postgres database in a data directory, and do not initdb if found
# assumes you have postgres_data_directory, postgres_user, and postgres_bin_directory set
- name: Check for existing database
become: yes
become_user: postgres
stat:
path: "{{ postgres_data_directory }}/PG_VERSION"
register: pgdata_directory_version
- name: Initialize PostgreSQL DB
become: yes
become_user: "{{ postgres_user }}"
command: "{{ postgres_bin_directory }}/initdb -D {{ postgres_data_directory }}"
when: not pgdata_directory_version.stat.exists
# https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment