# CLDR Commit Checker playbook
- hosts: ccc
  become: yes
  vars_files:
    - vars/main.yml
    - local-vars/local.yml
  tasks:
    - name: ensure cldrcc group is there
      group:
        name: cldrcc
        state: present
    - name: ensure cldrcc user is there
      user:
        name: cldrcc
        groups:
          - cldrcc
        append: yes # add to the groups, do not remove
        state: present
        create_home: true
    - name: set up /home/cldrcc/.ssh/
      file:
        path: /home/cldrcc/.ssh/
        owner: cldrcc
        group: cldrcc
        mode: '0700'
        state: directory
    - name: set up /home/cldrcc/.ssh/authorized_keys
      copy:
        src: local-vars/cldrcc/id_rsa.pub
        dest: /home/cldrcc/.ssh/authorized_keys
        owner: cldrcc
        group: cldrcc
        mode: '0600'
    - name: set up /home/cldrcc/public_html/
      file:
        path: /home/cldrcc/public_html/
        owner: cldrcc
        group: cldrcc
        mode: '0755'
        state: directory
    - name: set up github-markdown.css
      get_url:
        dest: /home/cldrcc/public_html/github-markdown.css
        owner: cldrcc
        group: cldrcc
        mode: '0644'
        force: no
        url: https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css
        # from https://github.com/sindresorhus/github-markdown-css
    - name: Setup publication and indexing
      blockinfile:
        path: /etc/nginx/sites-enabled/default
        block: |
          # commit checker
          location ~ ^/cldrcc/(.*)$ {
                charset utf-8;
                source_charset utf-8;
                alias /home/cldrcc/public_html/$1;
                autoindex on;
          }
        marker: '# {mark} ANSIBLE MANAGED COMMIT CHECKER BLOCK'
        insertafter: '^[\s]*server_name' # the LAST uncommented server block
      notify: 'Restart Nginx Again'
  handlers:
    - name: Restart Nginx Again
      service:
        name: nginx
        state: restarted
