- name: check/create instance
  hosts: artboard.fedorainfracloud.org
  gather_facts: False

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - /srv/private/ansible/vars.yml
   - /srv/web/infra/ansible/vars/fedora-cloud.yml
   - /srv/private/ansible/files/openstack/passwords.yml

  tasks:
  - import_tasks: "{{ tasks_path }}/persistent_cloud.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: setup all the things
  hosts: artboard.fedorainfracloud.org
  gather_facts: True
  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - /srv/private/ansible/vars.yml
   - /srv/private/ansible/files/openstack/passwords.yml
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - import_tasks: "{{ tasks_path }}/cloud_setup_basic.yml"
  - name: set hostname (required by some services, at least postfix need it)
    hostname: name="{{inventory_hostname}}"

  roles:
  - basessh

  tasks:

  - name: Install common scripts
    copy: src={{ item }} dest=/usr/local/bin/ owner=root group=root mode=0755
    with_fileglob:
    - "{{ roles_path }}/base/files/common-scripts/*"
    tags:
    - config
    - base
    - artboard

  - name: set sebooleans so artboard can talk to the db
    seboolean: name=httpd_can_network_connect_db state=true persistent=true
    tags:
    - selinux
    - artboard

  - name: mount up disk of persistent storage
    mount: name=/srv/persist src='LABEL=artboard' fstype=ext4 state=mounted
    tags:
    - artboard

  - name: check the selinux context of the artboard dirs
    command: matchpathcon "/srv/persist/artboard/(.*)"
    register: webcontext
    check_mode: no
    changed_when: false
    tags:
    - config
    - selinux
    - artboard

  - name: set the SELinux policy for the artboard web dir
    command: semanage fcontext -a -t httpd_sys_content_t "/srv/persist/artboard/(.*)"
    when: webcontext.stdout.find('httpd_sys_content_t') == -1
    tags:
    - config
    - selinux
    - artboard

  # packages needed
  - name: add packages
    package: state=present name={{ item }}
    with_items:
    - rsync
    - openssh-clients
    - httpd
    - httpd-tools
    - php
    - php-gd
    - php-mysql
    - cronie-noanacron
    - mod_ssl
    tags:
    - artboard

  # packages needed to be gone
  - name: erase packages
    package: state=absent name={{ item }}
    with_items:
    - cronie-anacron
    tags:
    - artboard

  - name: artboard backup thing
    copy: src="{{ files }}/artboard/artboard-backup" dest=/etc/cron.daily/artboard-backup mode=0755
    tags:
    - artboard

  - name: make artboard subdir
    file: path=/srv/persist/artboard mode=0755 state=directory
    tags:
    - artboard

  - name: link artboard into /var/www/html
    file: state=link src=/srv/persist/artboard path=/var/www/html/artboard
    tags:
    - artboard

  - name: add apache confs
    copy: src="{{ files }}/artboard/{{ item }}" dest="/etc/httpd/conf.d/{{ item }}"  backup=true
    with_items:
    - artboard.conf
    - redirect.conf
    notify: reload httpd
    tags:
    - artboard

  - name: startup apache
    service: name=httpd state=started
    tags:
    - artboard

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
