---

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - git
  - nodejs
  - npm
  tags:
  - packages

- name: Clone the regcfp master branch
  git: repo=https://github.com/puiterwijk/regcfp.git
       dest=/srv/regcfp
       version=flock2017
       clone=yes update=yes
  register: git_result
  changed_when: "git_result.after|default('after') != git_result.before|default('before')"
  tags:
  - regcfp
  notify:
  - restart regcfp

# TODO: Find EPEL packages for these
- name: Install dependencies
  command: /bin/npm install
           chdir=/srv/regcfp
  register: deps
  changed_when: "deps.stdout|length > 0"
  tags:
  - regcfp

- name: copy over the server config
  template: src=config.json dest=/srv/regcfp/config/config.json mode=0640
  tags:
  - regcfp
  notify:
  - restart regcfp

- name: Copy over the ftf certs
  copy: src="{{private}}/files/httpd/{{item}}"
        dest=/etc/pki/tls/certs
  with_items:
  - flocktofedora.org.cert
  - flocktofedora.org.intermediate.cert
  tags:
  - regcfp
  notify:
  - restart regcfp

- name: Copy over the ftf cert key
  copy: src="{{private}}/files/httpd/flocktofedora.org.key"
        dest=/etc/pki/tls/private
  tags:
  - regcfp
  notify:
  - restart regcfp

- name: copy over the systemd file
  copy: src=regcfp.service dest=/etc/systemd/system/regcfp.service mode=0640
  tags:
  - regcfp
  notify:
  - restart regcfp

- name: regcfp service
  service: name=regcfp state=started enabled=yes
  tags:
  - regcfp
