main.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # This role installs and prepares PostgreSQL for KEA DHCP Server
  2. ---
  3. - name: adding pub key for postgres repo
  4. apt_key:
  5. id: ACCC4CF8
  6. url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
  7. when: domaenenliste is defined
  8. - name: Add official postgres repo
  9. apt_repository:
  10. repo: "deb http://apt.postgresql.org/pub/repos/apt/ {{ansible_distribution_release}}-pgdg main"
  11. when: domaenenliste is defined
  12. - name: Install PostgreSQL
  13. apt:
  14. name: "{{item}}"
  15. update_cache: yes
  16. cache_valid_time: 1800
  17. state: present
  18. with_items:
  19. - postgresql-9.5
  20. - python-psycopg2
  21. - python3-psycopg2
  22. - sudo
  23. when: domaenenliste is defined
  24. - name: Configure PostgreSQL
  25. template:
  26. src: "{{item}}"
  27. dest: "/etc/postgresql/9.5/main/{{item[:-3]}}"
  28. with_items:
  29. - postgresql.conf.j2
  30. - pg_ctl.conf.j2
  31. - environment.j2
  32. - pg_hba.conf.j2
  33. - pg_ident.conf.j2
  34. notify: restart postgres
  35. when: domaenenliste is defined
  36. - name: Create database for dhcp leases
  37. postgresql_db:
  38. name: kea_leases
  39. become: yes
  40. become_user: postgres
  41. register: _kea_leses_db_created
  42. when: domaenenliste is defined
  43. - name: Create kea user and grant all privileges to kea_leases database
  44. postgresql_user:
  45. db: kea_leases
  46. name: kea
  47. password: "{{kea_postgres_pw}}"
  48. priv: ALL
  49. become: yes
  50. become_user: postgres
  51. when: domaenenliste is defined
  52. - name: Initialize kea_leases database
  53. shell: "kea-admin lease-init pgsql -u kea -p {{kea_postgres_pw}} -n kea_leases"
  54. when:
  55. - domaenenliste is defined
  56. - "_kea_leses_db_created.changed == True"
  57. - name: enable PostreSQL service
  58. service: name=postgresql enabled=yes state=started
  59. when: domaenenliste is defined