|
| 1 | +--- |
| 2 | +- name: Create secret for cookie encryption. |
| 3 | + set_fact: |
| 4 | + meshmage_secret: "{{ lookup('password', '/dev/null chars=hexdigits length=40') }}" |
| 5 | + when: meshmage_secret is undefined |
| 6 | + |
| 7 | +- name: Create postgres password. |
| 8 | + set_fact: |
| 9 | + postgresql_password: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=32') }}" |
| 10 | + when: postgresql_password is undefined |
| 11 | + |
| 12 | +- name: Update all packages to their latest version |
| 13 | + apt: |
| 14 | + name: "*" |
| 15 | + state: latest |
| 16 | + update_cache: yes |
| 17 | + |
| 18 | +- name: Install packages for key exchange. |
| 19 | + apt: |
| 20 | + name: [ |
| 21 | + 'apt-transport-https', |
| 22 | + 'ca-certificates', |
| 23 | + 'curl', |
| 24 | + 'gnupg', |
| 25 | + 'lsb-release' |
| 26 | + ] |
| 27 | + state: present |
| 28 | + |
| 29 | +- name: Install packages |
| 30 | + apt: |
| 31 | + name: [ |
| 32 | + 'git', |
| 33 | + 'build-essential', |
| 34 | + 'libpq-dev', |
| 35 | + 'libssl-dev', |
| 36 | + 'libz-dev', |
| 37 | + 'cpanminus', |
| 38 | + 'liblocal-lib-perl', |
| 39 | + 'kitty-terminfo', |
| 40 | + ] |
| 41 | + state: present |
| 42 | + |
| 43 | +- name: Create onw user |
| 44 | + user: |
| 45 | + name: onw |
| 46 | + shell: /bin/bash |
| 47 | + comment: OpenNewsWire User Account |
| 48 | + |
| 49 | +- name: Create ~onw/.ssh |
| 50 | + file: |
| 51 | + state: directory |
| 52 | + path: /home/onw/.ssh |
| 53 | + owner: onw |
| 54 | + group: onw |
| 55 | + mode: 0700 |
| 56 | + |
| 57 | +- name: Create ~onw/.ssh/authorized_keys from ~root |
| 58 | + copy: |
| 59 | + dest: /home/onw/.ssh/authorized_keys |
| 60 | + src: /root/.ssh/authorized_keys |
| 61 | + remote_src: true |
| 62 | + owner: onw |
| 63 | + group: onw |
| 64 | + mode: 0600 |
| 65 | + |
| 66 | +- name: Setup local::lib for meshmage. |
| 67 | + lineinfile: |
| 68 | + path: /home/onw/.bashrc |
| 69 | + line: 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' |
| 70 | + create: yes |
| 71 | + |
| 72 | +- name: Install perl modules (up to 3 tries) |
| 73 | + shell: cpanm App::plx App::opan App::Dex Carton Dist::Zilla |
| 74 | + args: |
| 75 | + chdir: /home/onw |
| 76 | + executable: /bin/bash |
| 77 | + environment: |
| 78 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 79 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 80 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 81 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 82 | + retries: 3 |
| 83 | + register: result |
| 84 | + until: result.rc == 0 |
| 85 | + become: true |
| 86 | + become_user: onw |
| 87 | + |
| 88 | +- name: Checkout OpenNewsWire repo. |
| 89 | + shell: git clone https://github.com/symkat/OpenNewsWire.git |
| 90 | + args: |
| 91 | + creates: /home/onw/OpenNewsWire |
| 92 | + chdir: /home/onw |
| 93 | + executable: /bin/bash |
| 94 | + environment: |
| 95 | + GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 96 | + become: true |
| 97 | + become_user: onw |
| 98 | + |
| 99 | +- name: Build OpenNewsWire::DB |
| 100 | + shell: dzil build |
| 101 | + args: |
| 102 | + chdir: /home/onw/OpenNewsWire/Database |
| 103 | + executable: /bin/bash |
| 104 | + environment: |
| 105 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 106 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 107 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 108 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 109 | + become: true |
| 110 | + become_user: onw |
| 111 | + |
| 112 | +- name: Install OpenNewsWire::DB |
| 113 | + shell: cpanm OpenNewsWire-DB-*.tar.gz |
| 114 | + args: |
| 115 | + chdir: /home/onw/OpenNewsWire/Database |
| 116 | + executable: /bin/bash |
| 117 | + environment: |
| 118 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 119 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 120 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 121 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 122 | + retries: 3 |
| 123 | + register: result |
| 124 | + until: result.rc == 0 |
| 125 | + become: true |
| 126 | + become_user: onw |
| 127 | + |
| 128 | +- name: Configure plx for OpenNewsWire::Web |
| 129 | + shell: | |
| 130 | + plx --init |
| 131 | + plx --config libspec add 00tilde.ll $HOME/perl5 |
| 132 | + plx --config libspec add 40dblib.dir ../Database/lib |
| 133 | + plx opan init |
| 134 | + plx opan add ../DB/OpenNewsWire-DB-*.tar.gz |
| 135 | + plx opan merge |
| 136 | + args: |
| 137 | + creates: /home/onw/OpenNewsWire/Web/.plx |
| 138 | + chdir: /home/onw/OpenNewsWire/Web |
| 139 | + executable: /bin/bash |
| 140 | + environment: |
| 141 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 142 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 143 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 144 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 145 | + become: true |
| 146 | + become_user: onw |
| 147 | + |
| 148 | +- name: Install dependancies for OpenNewsWire::Web |
| 149 | + shell: plx opan carton install |
| 150 | + args: |
| 151 | + chdir: /home/onw/OpenNewsWire/Web |
| 152 | + environment: |
| 153 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 154 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 155 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 156 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 157 | + retries: 3 |
| 158 | + register: result |
| 159 | + until: result.rc == 0 |
| 160 | + become: true |
| 161 | + become_user: onw |
| 162 | + |
| 163 | +# Setup the databases |
| 164 | + |
| 165 | +- name: Install Database Packages |
| 166 | + apt: |
| 167 | + name: [ |
| 168 | + 'postgresql-client', |
| 169 | + 'postgresql-contrib', |
| 170 | + 'postgresql', |
| 171 | + 'python3-psycopg2', |
| 172 | + ] |
| 173 | + state: present |
| 174 | + |
| 175 | +- name: start postgresql |
| 176 | + service: name=postgresql state=started enabled=true |
| 177 | + |
| 178 | +- name: Create PSQL user account. |
| 179 | + postgresql_user: |
| 180 | + name: "{{ postgresql_user }}" |
| 181 | + password: "{{ postgresql_password }}" |
| 182 | + state: present |
| 183 | + become_user: postgres |
| 184 | + become: true |
| 185 | + |
| 186 | +- name: Create PSQL database. |
| 187 | + postgresql_db: |
| 188 | + name: "{{ postgresql_database }}" |
| 189 | + owner: "{{ postgresql_user }}" |
| 190 | + state: present |
| 191 | + become_user: postgres |
| 192 | + become: true |
| 193 | + register: postgresql_create_database |
| 194 | + |
| 195 | +- name: Enable citext on database. |
| 196 | + postgresql_query: |
| 197 | + db: "{{ postgresql_database }}" |
| 198 | + query: CREATE EXTENSION IF NOT EXISTS citext |
| 199 | + become_user: postgres |
| 200 | + become: true |
| 201 | + |
| 202 | +- name: Write /etc/dbic.yaml file. |
| 203 | + template: |
| 204 | + src: "{{ role_path }}/templates/dbic.yaml.j2" |
| 205 | + dest: /etc/dbic.yaml |
| 206 | + owner: onw |
| 207 | + group: onw |
| 208 | + mode: '0640' |
| 209 | + |
| 210 | +- name: Overwrite /home/onw/OpenNewsWire/Web/dbic.yaml file. |
| 211 | + template: |
| 212 | + src: "{{ role_path }}/templates/dbic.yaml.j2" |
| 213 | + dest: /home/onw/OpenNewsWire/Web/dbic.yaml |
| 214 | + owner: onw |
| 215 | + group: onw |
| 216 | + mode: '0640' |
| 217 | + |
| 218 | +- name: Check if ddl directory exists. |
| 219 | + stat: |
| 220 | + path: /home/onw/OpenNewsWire/Database/etc/ddl/PostgreSQL/deploy |
| 221 | + register: ddl_dir |
| 222 | + |
| 223 | +- name: Write Database DDL |
| 224 | + shell: ./bin/opennewswire-db-deploy write_ddl |
| 225 | + args: |
| 226 | + chdir: /home/onw/OpenNewsWire/Database |
| 227 | + environment: |
| 228 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 229 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 230 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 231 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 232 | + become: true |
| 233 | + become_user: onw |
| 234 | + when: ddl_dir.exists is not defined |
| 235 | + |
| 236 | +- name: Install Database DDL |
| 237 | + shell: ./bin/opennewswire-db-deploy install |
| 238 | + args: |
| 239 | + chdir: /home/onw/OpenNewsWire/Database |
| 240 | + environment: |
| 241 | + PERL_MB_OPT: "--install_base \"/home/onw/perl5\"" |
| 242 | + PERL_MM_OPT: "INSTALL_BASE=/home/onw/perl5" |
| 243 | + PERL5LIB: "/home/onw/perl5/lib/perl5" |
| 244 | + PATH: "/home/onw/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" |
| 245 | + become: true |
| 246 | + become_user: onw |
| 247 | + when: ddl_dir.exists is not defined |
| 248 | + |
| 249 | +- name: Install opennewswire.service file. |
| 250 | + copy: |
| 251 | + dest: /etc/systemd/system/opennewswire.service |
| 252 | + src: "{{ role_path }}/files/opennewswire.service" |
| 253 | + owner: root |
| 254 | + group: root |
| 255 | + mode: 0644 |
| 256 | + |
| 257 | +- name: Start OpenNewsWire |
| 258 | + service: |
| 259 | + name: opennewswire |
| 260 | + state: started |
| 261 | + enabled: true |
| 262 | + |
| 263 | + |
| 264 | +# Setup the web server |
| 265 | + |
| 266 | +- name: Install Web Server Packages |
| 267 | + apt: |
| 268 | + name: [ |
| 269 | + 'nginx', |
| 270 | + 'certbot', |
| 271 | + 'python3-certbot-dns-linode', |
| 272 | + 'python-certbot-dns-linode-doc', |
| 273 | + ] |
| 274 | + state: present |
| 275 | + |
| 276 | +- name: "Write /etc/nginx/sites-enabled/{{ nginx_domain }}" |
| 277 | + template: |
| 278 | + src: "{{ role_path }}/templates/nginx-site.conf.j2" |
| 279 | + dest: "/etc/nginx/sites-enabled/{{ nginx_domain }}" |
| 280 | + owner: root |
| 281 | + group: root |
| 282 | + mode: '0644' |
| 283 | + |
| 284 | +- name: start nginx |
| 285 | + service: |
| 286 | + name: nginx |
| 287 | + state: started |
| 288 | + enabled: true |
0 commit comments