Skip to content
Snippets Groups Projects
main.yml 6.67 KiB
Newer Older
  • Learn to ignore specific revisions
  • ---
    
    - name: install git
    
      pacman: name=git,python2,python2-virtualenv,uwsgi-plugin-python2 state=present
    
    - name: make archweb user
    
      user: name=archweb shell=/bin/false home="{{ archweb_dir }}" createhome=no groups=uwsgi
    
    
    - name: fix home permissions
    
      file: state=directory owner=archweb group=archweb path="{{ archweb_dir }}"
    
    - name: set up nginx
      template: src=nginx.d.conf.j2 dest=/etc/nginx/nginx.d/archweb.conf owner=root group=root mode=644
      notify:
        - restart nginx
    
    
    - name: make nginx log dir
      file: path=/var/log/nginx/{{ archweb_domain }} state=directory owner=http group=log mode=755
    
    
    - name: clone archweb repo
    
      git: repo=git://git.archlinux.org/archweb.git dest="{{ archweb_dir }}"
    
      become: true
      become_user: archweb
    
    
    - name: make virtualenv
    
      command: virtualenv2 "{{ archweb_dir }}"/env creates="{{ archweb_dir }}/env/bin/python"
    
      become: true
      become_user: archweb
    
    - name: install stuff into virtualenv
    
      pip: requirements="{{ archweb_dir }}/requirements_prod.txt" virtualenv="{{ archweb_dir }}/env"
    
      become: true
      become_user: archweb
    
    
    - name: create media dir
      file: state=directory owner=archweb group=archweb path="{{ archweb_dir }}/media"
    
    - name: fix home permissions
    
      file: state=directory owner=archweb group=archweb path="{{ archweb_dir }}"
    
    - name: configure archweb
      template: src=local_settings.py.j2 dest=/srv/http/archweb/local_settings.py owner=archweb group=archweb mode=0660
      no_log: true
    
    
    - name: create archweb db users
      postgresql_user: name={{ item.user }} password={{ item.password }} login_host="{{ archweb_db_host }}" login_password="{{ postgres_users.postgres }}" encrypted=yes
      no_log: true
      with_items:
        - { user: "{{ archweb_db_site_user }}", password: "{{ archweb_db_site_password }}" }
        - { user: "{{ archweb_db_services_user }}", password: "{{ archweb_db_services_password }}" }
        - { user: "{{ archweb_db_dbscripts_user }}", password: "{{ archweb_db_dbscripts_password }}" }
        - { user: "{{ archweb_db_backup_user }}", password: "{{ archweb_db_backup_password }}" }
    
    - name: create archweb db
      postgresql_db: name="{{ archweb_db }}" login_host="{{ archweb_db_host }}" login_password="{{ postgres_users.postgres }}" owner="{{ archweb_db_site_user }}"
      register: db_created
    
    - name: django syncdb
      django_manage: app_path="{{ archweb_dir }}" command=syncdb virtualenv="{{ archweb_dir }}/env"
      become: true
      become_user: archweb
      when: db_created.changed
    
    - name: django migrate
      django_manage: app_path="{{ archweb_dir }}" command=migrate virtualenv="{{ archweb_dir }}/env"
      become: true
      become_user: archweb
      when: archweb_site and (db_created.changed or release.changed)
    
    
    - name: db privileges for archweb users
      postgresql_privs: database="{{ archweb_db }}" host="{{ archweb_db_host }}" login="{{ archweb_db_site_user }}" password="{{ archweb_db_site_password }}"
                        privs=CONNECT roles="{{ item }}" type=database
      with_items:
        - "{{ archweb_db_services_user }}"
        - "{{ archweb_db_dbscripts_user }}"
        - "{{ archweb_db_backup_user }}"
    
    - name: table privileges for archweb users
      postgresql_privs: database="{{ archweb_db }}" host="{{ archweb_db_host }}" login="{{ archweb_db_site_user }}" password="{{ archweb_db_site_password }}"
                        privs=SELECT roles="{{ item.user }}" type=table objs="{{ item.objs }}"
      with_items:
        - { user: "{{ archweb_db_services_user }}", objs: "{{ archweb_db_services_table_objs }}" }
        - { user: "{{ archweb_db_dbscripts_user }}", objs: "{{ archweb_db_dbscripts_table_objs }}" }
        - { user: "{{ archweb_db_backup_user }}", objs: "{{ archweb_db_backup_table_objs }}" }
    
    - name: sequence privileges for archweb users
      postgresql_privs: database="{{ archweb_db }}" host="{{ archweb_db_host }}" login="{{ archweb_db_site_user }}" password="{{ archweb_db_site_password }}"
                        privs=SELECT roles="{{ item.user }}" type=sequence objs="{{ item.objs }}"
      with_items:
        - { user: "{{ archweb_db_services_user }}", objs: "{{ archweb_db_services_sequence_objs }}" }
        - { user: "{{ archweb_db_backup_user }}", objs: "{{ archweb_db_backup_sequence_objs }}" }
    
    
    - name: django collectstatic
      django_manage: app_path="{{ archweb_dir }}" command=collectstatic virtualenv="{{ archweb_dir }}/env"
      become: true
      become_user: archweb
      when: archweb_site and (db_created.changed or release.changed)
    
    
    - name: install reporead service
      template: src="archweb-reporead.service.j2" dest="/etc/systemd/system/archweb-reporead.service" owner=root group=root mode=0644
      notify:
        - daemon reload
    
      template: src="archweb-mirrorcheck.service.j2" dest="/etc/systemd/system/archweb-mirrorcheck.service" owner=root group=root mode=0644
      notify:
        - daemon reload
    
    
    - name: install mirrorcheck timer
      template: src="archweb-mirrorcheck.timer.j2" dest="/etc/systemd/system/archweb-mirrorcheck.timer" owner=root group=root mode=0644
    
      notify:
        - daemon reload
    
    - name: install pgp_import service
      template: src="archweb-pgp_import.service.j2" dest="/etc/systemd/system/archweb-pgp_import.service" owner=root group=root mode=0644
      notify:
        - daemon reload
      when: archweb_services or archweb_pgp_import
    
    - name: create pacman.d hooks dir
      file: state=directory owner=root group=root path="/etc/pacman.d/hooks"
      when: archweb_services or archweb_pgp_import
    
    - name: install pgp_import hook
      template: src="archweb-pgp_import-pacman-hook.j2" dest="/etc/pacman.d/hooks/archweb-pgp_import.hook" owner=root group=root mode=0644
      when: archweb_services or archweb_pgp_import
    
    
    - name: install archweb memcached service
      template: src="archweb-memcached.service.j2" dest="/etc/systemd/system/archweb-memcached.service" owner=root group=root mode=0644
    
    - name: deploy archweb
      template: src=archweb.ini.j2 dest=/etc/uwsgi/vassals/archweb.ini owner=archweb group=http mode=0644
    
    - name: deploy new release
      become: true
      become_user: archweb
      file: path=/etc/uwsgi/vassals/archweb.ini state=touch
      when: archweb_site and release.changed
    
    
    - name: start and enable archweb memcached service
      service: name="archweb-memcached.service" enabled=yes state=started
    
    - name: start and enable archweb reporead service
      service: name="archweb-reporead.service" enabled=yes state=started
      when: archweb_services or archweb_reporead
    
    - name: start and enable archweb mirrorcheck timer
      service: name="archweb-mirrorcheck.timer" enabled=yes state=started
      when: archweb_services or archweb_mirrorcheck