summaryrefslogtreecommitdiffstats
path: root/roles/copr/mbs/tasks/main.yml
blob: 2057693e663237aa29f6fc16e32cd5107c0257f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# @TODO
#
# - I am currently storing my personal token in /etc/module-build-service/copr.conf
#   and also my personal login in /etc/module-build-service/config.py
#
# - I am currently running mbs-frontend manually
#     - Because of issue with <Location> in httpd config. See coprs.conf

---

# Cant use the ansible dnf module here. It doesnt work without these pacakges.
# Therefore using command module
- name: Install python and deps for ansible modules
  command: dnf install --refresh -y python2 python2-dnf libselinux-python


- name: Enable copr repo
  command: dnf -y copr enable @copr/copr

- name: Install stuff
  dnf: name={{ item }} state=latest
  with_items:
    # Those things are explicitly listed in Vagrantfile
    # https://pagure.io/fm-orchestrator/blob/master/f/Vagrantfile
    # Should they be covered by spec file?
    - fedmsg-hub
    - fedmsg-relay
    - fedpkg
    - gcc
    - gcc
    - gcc-c++
    - krb5-workstation
    - libffi-devel
    - openssl-devel
    - python-virtualenv
    - redhat-rpm-config
    - redhat-rpm-config
    - swig
    - systemd-devel

    # Not covered by Vagrantfile nor .spec file,
    # but it seems to be required
    - python-systemd

    # Required for copr
    - copr-cli
    - python-copr


- name: Install module-build-service package
  #dnf: name=module-build-service state=latest
  command: dnf -y install https://kojipkgs.fedoraproject.org//packages/module-build-service/1.1.0/3.fc26/noarch/module-build-service-1.1.0-3.fc26.noarch.rpm



# Post-install stuff

# We need to remove this file or otherwise MBS Builder code is not executed at all
- name: Remove /etc/fedmsg.d/relay.py
  file: path=/etc/fedmsg.d/relay.py state=absent

# We want to run fedmsg-hub as 'mbs' user, because we don't want to rpmbuild as 'fedmsg'
- name: Copy modified fedmsg-hub.service file
  copy: src=fedmsg-hub.service dest=/etc/systemd/system/fedmsg-hub.service
  notify: daemon reload


# Create user and group for mbs
- name: Create group for mbs-frontend
  group: name=mbs state=present gid=1002

- name: Create user for mbs-frontend
  user: name=mbs group=mbs uid=1002



# The config provided by MBS package is a python file
# Instead of replacing values by regex in such file, rather rename
# the original file and then install own configuration file which
# inherits the original one and then customizes it.
- name: Stat base_config
  stat: path=/etc/module-build-service/base_config.py
  register: base_config_stat

- name: Move config.py to base_config.py
  command: mv /etc/module-build-service/config.py /etc/module-build-service/base_config.py creates=/etc/module-build-service/base_config.py

- name: Touch __init__.py file
  file: path=/etc/module-build-service/__init__.py state=touch

- name: Copy production config
  template: src=config.py dest=/etc/module-build-service/config.py

- name: Copy config for copr-cli
  template: src=copr.conf dest=/etc/module-build-service/copr.conf

- name: Install client_secrets.json
  template: src=client_secrets.json dest=/etc/module-build-service/


- name: Upgrade database
  command: mbs-upgradedb

- name: Generate cert
  command: mbs-gencert
  args:
    creates: /etc/module-build-service/server.crt

- name: generate cacert.pem
  shell: cat /etc/module-build-service/server.crt /etc/module-build-service/server.key > /etc/module-build-service/cacert.pem
  args:
    creates: /etc/module-build-service/cacert.pem

- name: Chown /etc/module-build-service to mbs:mbs
  file: path=/etc/module-build-service owner=mbs group=mbs recurse=yes mode=g+w

- name: Add copr-fe to mbs group
  user: name=copr-fe groups=mbs append=yes


# Run module-build-service processes
- name: Enable fedmsg-relay
  service: name=fedmsg-relay enabled=yes state=started

- name: Run fedmsg-hub
  service: name=fedmsg-hub enabled=yes state=started



# Prepare and run MBS frontend
- name: Create /opt/module-build-service
  file:  path=/opt/module-build-service state=directory

- name: Copy mbs.wsgi file
  copy: src=mbs.wsgi dest=/opt/module-build-service/mbs.wsgi

- name: Create vhosts directory
  file: path=/etc/httpd/conf/vhosts/mbs state=directory

- name: Copy httpd/mbs.conf to vhosts directory
  copy: src=httpd/mbs.conf dest=/etc/httpd/conf/vhosts/mbs/mbs.conf
  notify: reload httpd



# Only for testing purposes
# Use it as:  python submit_build.py 127.0.0.1:5000
- name: Download submit_build.py
  get_url: url=https://pagure.io/fm-orchestrator/raw/master/f/contrib/submit_build.py dest=./
  when: devel

- name: Download submit-build.json
  get_url: url=https://pagure.io/fm-orchestrator/raw/master/f/contrib/submit-build.json dest=./
  when: devel

# A slightly modified submit_build.py to work with our httpd configuration
- name: Download submit_build_copr.py
  get_url: url=https://gist.githubusercontent.com/FrostyX/ba15f60b4b4c8d2dfae6e3eaba56df61/raw/28d50f9c419bf925f88ebd91aba6d6f7e0e64672/submit_build_copr.py dest=./
  when: devel


# In this point personal information needs to be manually set, as described in @TODO at the beggining of the file
# The frontend process needs to be restarted. Then it is possible to submit new module build.
# Run:  python submit_build_copr.py 127.0.0.1