init.yml 2.74 KB
Newer Older
1
---
2
- name: Initialize applications
3 4 5 6 7 8 9 10 11 12 13 14 15 16
  become: false
  gather_facts: false

  hosts:
    - apps

  vars:
    known_users:
      cyril:
        urlid: https://api.lepool.hubl.world/users/cyrilthiriet/
      jbpasquier:
        urlid: https://api.community.startinblox.com/users/jbpasquier/
      plup:
        urlid: https://api.paris.happy-dev.fr/users/plup/
17 18 19
        email: plup@plup.io
      marjolaine:
        email: marjolaine@startinblox.com
Plup's avatar
Plup committed
20 21
      sylvain:
        email: sylvain.zorninger@startinblox.com
22 23
      victoire:
        email: victoire@startinblox.com
Plup's avatar
Plup committed
24 25
      berengere:
        email: berengere@startinblox.com
26

27
  tasks:
28

29
    - name: Create a remote admin
30 31 32 33 34 35 36 37 38 39 40
      command: "python manage.py create_distant_admin --urlid='{{ known_users[user].urlid }}'"
      environment:
        PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
      args:
        chdir: "{{ home }}/sibserver"
      when: not ansible_check_mode
      tags:
        - never
        - create_admin

    - name: Create a local admin
41 42
      shell:
        cmd: "echo \"from django.contrib.auth import get_user_model; CustomUser = get_user_model(); CustomUser.objects.create_superuser('{{ user }}', '{{ known_users[user].email }}', '{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=8') }}')\" | python manage.py shell"
43 44 45 46 47 48 49
      environment:
        PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
      args:
        chdir: "{{ home }}/sibserver"
      register: superuser_cmd
      failed_when:
        - superuser_cmd.rc != 0
50
        - "'already exists' not in superuser_cmd.stderr"
51
      changed_when:
52
        - superuser_cmd.rc == 0
53 54 55 56 57
      when: not ansible_check_mode
      tags:
        - never
        - create_local_admin

58 59 60 61 62 63 64 65 66 67 68 69 70
    - name: Federate applications
      vars:
        target_instances: "{{ groups['hublworld'] }}"
      command: "python manage.py federate --target https://{{ hostvars[item].services.api }}"
      environment:
        PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
      args:
        chdir: "{{ home }}/sibserver/"
      loop: "{{ target_instances }}"
      register: cmd
      when: not ansible_check_mode
      changed_when: cmd.rc == 0
      failed_when: cmd.rc > 1
71 72
      tags:
        - never
73
        - federate
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    - name: Defederate applications
      vars:
        target_instances: "{{ groups['hublworld'] }}"
      command: "python manage.py federate --delete https://{{ hostvars[item].services.api }}"
      environment:
        PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
      args:
        chdir: "{{ home }}/sibserver/"
      loop: "{{ target_instances }}"
      register: cmd
      when: not ansible_check_mode
      changed_when: cmd.rc == 0
      failed_when: cmd.rc > 1
      tags:
        - never
        - defederate