--- - block: - name: Create the user under pdns_admin will run user: name={{ pdns_admin_user }} home={{ pdns_admin_home }} createhome=no shell=/usr/sbin/nologin system=yes - name: Create the pdns_admin server base directory file: dest={{ item }} state=directory owner=root group=root with_items: - '{{ pdns_admin_home }}' - name: Create the pdns_admin server log directory file: dest={{ item }} state=directory owner={{ pdns_admin_user }} group={{ pdns_admin_user }} with_items: - '{{ pdns_admin_logdir }}' - name: Install the pdns_admin prerequisite deb packages apt: pkg={{ pdns_admin_prereqs }} state=present update_cache=yes cache_valid_time=1800 - name: Clone pdns_admin git: repo={{ pdns_admin_git_repo_url }} dest={{ pdns_admin_home }} update=no - name: Force the clone and upgrade pdns_admin when updating git: repo={{ pdns_admin_git_repo_url }} dest={{ pdns_admin_home }} update=yes force=yes when: pdns_admin_upgrade | bool - name: Remove the files that we use to skip the initialisation commands file: dest={{ item }} state=absent with_items: - '{{ pdns_admin_logdir }}/.db_initialised' - '{{ pdns_admin_home }}/app/static/generated/login.js' when: pdns_admin_upgrade | bool - name: Make the upload directory writeable by the pdnsadmin user file: dest={{ pdns_admin_home }}/upload recurse=yes owner={{ pdns_admin_user }} group={{ pdns_admin_user }} - name: Install the pdns_admin configuration template: src=config.py.j2 dest={{ pdns_admin_home }}/{{ pdns_admin_app_dir }}/default_config.py owner=root group={{ pdns_admin_user }} mode=0640 notify: Restart pdns_admin tags: [ 'pdns_admin', 'pdns_admin_config' ] - name: Create a python3 virtualenv shell: cd {{ pdns_admin_home }} ; virtualenv -p python3 flask args: creates: '{{ pdns_admin_home }}/flask' notify: Restart pdns_admin - name: Install the virtualenv requirements pip: requirements={{ pdns_admin_home }}/requirements.txt virtualenv={{ pdns_admin_home }}/flask virtualenv_site_packages=True notify: Restart pdns_admin - name: Install psycopg2 as an additional requirement pip: name=psycopg2-binary virtualenv={{ pdns_admin_home }}/flask notify: Restart pdns_admin - name: Initialise the database shell: cd {{ pdns_admin_home }}; . {{ pdns_admin_home }}/flask/bin/activate ; export FLASK_APP={{ pdns_admin_app_dir }}/__init__.py ; flask db upgrade && touch {{ pdns_admin_logdir }}/.db_initialised args: creates: '{{ pdns_admin_logdir }}/.db_initialised' - name: Create the assets files shell: cd {{ pdns_admin_home }}; . {{ pdns_admin_home }}/flask/bin/activate ; yarn install --pure-lockfile ; flask assets build args: creates: '{{ pdns_admin_home }}/app/static/generated/login.js' - name: Some directories must be writeable by the pdnsadmin user file: dest={{ item }} recurse=yes owner={{ pdns_admin_user }} group={{ pdns_admin_user }} with_items: - '{{ pdns_admin_home }}/{{ pdns_admin_app_dir }}/static/custom' - '{{ pdns_admin_home }}/{{ pdns_admin_app_dir }}/static/.webassets-cache' tags: pdns_admin when: pdns_admin_install - block: - name: Install the tmpfile configuration template: src=tmpfiles-powerdns-run.j2 dest=/usr/lib/tmpfiles.d/powerdns-admin.conf owner=root group=root - name: Install the pdns_admin server systemd units template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }} mode=0644 owner=root group=root with_items: - 'powerdns-admin.service' - 'powerdns-admin.socket' register: pdns_unit notify: Restart pdns_admin - name: Reload the systemd configuration systemd: daemon_reload=yes when: pdns_unit is changed - name: Ensure that pdns_admin is started and enabled service: name=powerdns-admin.socket state=started enabled=yes tags: [ 'pdns_admin', 'pdns_admin_service', 'pdns_admin_config' ] when: pdns_admin_install - block: - name: Ensure that pdns_admin is stopped and disabled service: name=powerdns-admin state=stopped enabled=no - name: Remove the pdns_admin init scripts file: dest=/etc/systemd/system/powerdns-admin.{{ item }} state=absent with_items: - 'service' - 'socket' - name: Remove all the pdns_admin files file: dest={{ item }} state=absent with_items: - '{{ pdns_admin_home }}' - '{{ pdns_admin_logdir }}' tags: pdns_admin when: not pdns_admin_install