|
| 1 | +--- |
| 2 | +- name: Set up local server |
| 3 | + hosts: all |
| 4 | + remote_user: vagrant |
| 5 | + become_user: root |
| 6 | + become_method: sudo |
| 7 | + vars: |
| 8 | + app_path: "/var/www/snipeit" |
| 9 | + fqdn: "localhost" |
| 10 | + tasks: |
| 11 | + - name: Update and upgrade existing apt packages |
| 12 | + become: true |
| 13 | + apt: |
| 14 | + upgrade: yes |
| 15 | + update_cache: yes |
| 16 | + - name: Install Utilities |
| 17 | + become: true |
| 18 | + apt: |
| 19 | + name: "{{ packages }}" |
| 20 | + state: present |
| 21 | + vars: |
| 22 | + packages: |
| 23 | + - nano |
| 24 | + - vim |
| 25 | + - name: Installing Apache httpd, PHP, MariaDB and other requirements. |
| 26 | + become: true |
| 27 | + apt: |
| 28 | + name: "{{ packages }}" |
| 29 | + state: present |
| 30 | + vars: |
| 31 | + packages: |
| 32 | + - mariadb-client |
| 33 | + - php |
| 34 | + - php-curl |
| 35 | + - php-mysql |
| 36 | + - php-gd |
| 37 | + - php-ldap |
| 38 | + - php-zip |
| 39 | + - php-mbstring |
| 40 | + - php-xml |
| 41 | + - php-bcmath |
| 42 | + - curl |
| 43 | + - git |
| 44 | + - unzip |
| 45 | + - python-pymysql |
| 46 | + # |
| 47 | + # Install the lastest version of composer |
| 48 | + # |
| 49 | + - name: Composer check |
| 50 | + stat: |
| 51 | + path: /usr/local/bin/composer |
| 52 | + register: composer_exits |
| 53 | + - name: Install Composer |
| 54 | + shell: | |
| 55 | + EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) |
| 56 | + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" |
| 57 | + ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');") |
| 58 | +
|
| 59 | + if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] |
| 60 | + then |
| 61 | + >&2 echo 'ERROR: Invalid installer signature' |
| 62 | + rm composer-setup.php |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + php composer-setup.php --quiet |
| 67 | + RESULT=$? |
| 68 | + rm composer-setup.php |
| 69 | + mv composer.phar /usr/local/bin/composer |
| 70 | + exit $RESULT |
| 71 | + when: not composer_exits.stat.exists |
| 72 | + args: |
| 73 | + creates: /usr/local/bin/composer |
| 74 | + become: true |
| 75 | + # |
| 76 | + # Install and Configure MariaDB |
| 77 | + # |
| 78 | + - name: Install MariaDB |
| 79 | + become: true |
| 80 | + apt: |
| 81 | + name: mariadb-server |
| 82 | + state: present |
| 83 | + register: sql_server |
| 84 | + - name: Start and Enable MySQL server |
| 85 | + become: true |
| 86 | + systemd: |
| 87 | + state: started |
| 88 | + enabled: yes |
| 89 | + name: mariadb |
| 90 | + - name: Create Vagrant mysql password |
| 91 | + become: true |
| 92 | + mysql_user: |
| 93 | + name: vagrant |
| 94 | + password: vagrant |
| 95 | + login_unix_socket: /var/run/mysqld/mysqld.sock |
| 96 | + priv: "*.*:ALL" |
| 97 | + state: present |
| 98 | + - name: Enable remote mysql |
| 99 | + replace: |
| 100 | + path: /etc/mysql/mariadb.conf.d/50-server.cnf |
| 101 | + regexp: "127.0.0.1" |
| 102 | + replace: "0.0.0.0" |
| 103 | + become: true |
| 104 | + notify: |
| 105 | + - restart mysql |
| 106 | + - name: Create snipeit database |
| 107 | + become: true |
| 108 | + mysql_db: |
| 109 | + name: snipeit |
| 110 | + state: present |
| 111 | + login_unix_socket: /var/run/mysqld/mysqld.sock |
| 112 | + # |
| 113 | + # Install Apache Web Server |
| 114 | + # |
| 115 | + - name: Install Apache 2.4 |
| 116 | + apt: |
| 117 | + name: "{{ packages }}" |
| 118 | + state: present |
| 119 | + vars: |
| 120 | + packages: |
| 121 | + - apache2 |
| 122 | + - libapache2-mod-php |
| 123 | + become: true |
| 124 | + register: apache2_server |
| 125 | + - name: Start and Enable Apache2 Server |
| 126 | + become: true |
| 127 | + systemd: |
| 128 | + name: apache2 |
| 129 | + state: started |
| 130 | + enabled: yes |
| 131 | + #- name: Disable Apache modules |
| 132 | + # become: true |
| 133 | + # apache2_module: |
| 134 | + # state: absent |
| 135 | + # name: "{{ item }}" |
| 136 | + # with_items: |
| 137 | + # #- mpm_prefork |
| 138 | + # notify: |
| 139 | + # - restart apache2 |
| 140 | + - name: Enable Apache modules |
| 141 | + become: true |
| 142 | + apache2_module: |
| 143 | + state: present |
| 144 | + name: "{{ item }}" |
| 145 | + with_items: |
| 146 | + - rewrite |
| 147 | + - vhost_alias |
| 148 | + - deflate |
| 149 | + - expires |
| 150 | + - proxy_fcgi |
| 151 | + - proxy |
| 152 | + notify: |
| 153 | + - restart apache2 |
| 154 | + - name: Install Apache VirtualHost File |
| 155 | + become: true |
| 156 | + template: |
| 157 | + src: apachevirtualhost.conf.j2 |
| 158 | + dest: "/etc/apache2/sites-available/snipeit.conf" |
| 159 | + - name: Enable VirtualHost |
| 160 | + become: true |
| 161 | + command: a2ensite snipeit |
| 162 | + args: |
| 163 | + creates: /etc/apache2/sites-enabled/snipeit.conf |
| 164 | + notify: |
| 165 | + - restart apache2 |
| 166 | + - name: Map apache dir to local folder |
| 167 | + become: true |
| 168 | + file: |
| 169 | + src: /vagrant |
| 170 | + dest: "{{ app_path }}" |
| 171 | + state: link |
| 172 | + notify: |
| 173 | + - restart apache2 |
| 174 | + # |
| 175 | + # Install dependencies from composer |
| 176 | + # |
| 177 | + - name: Install dependencies from composer |
| 178 | + composer: |
| 179 | + command: install |
| 180 | + working_dir: "{{ app_path }}" |
| 181 | + notify: |
| 182 | + - restart apache2 |
| 183 | + # |
| 184 | + # Configure .env file |
| 185 | + # |
| 186 | + - name: Copy .env file |
| 187 | + copy: |
| 188 | + src: "{{ app_path }}/.env.example" |
| 189 | + dest: "{{ app_path }}/.env" |
| 190 | + - name: Configure .env file |
| 191 | + lineinfile: |
| 192 | + path: "{{ app_path }}/.env" |
| 193 | + regexp: "{{ item.regexp }}" |
| 194 | + line: "{{ item.line }}" |
| 195 | + with_items: |
| 196 | + - { regexp: '^DB_HOST=', line: 'DB_HOST=127.0.0.1'} |
| 197 | + - { regexp: '^DB_DATABASE=', line: 'DB_DATABASE=snipeit' } |
| 198 | + - { regexp: '^DB_USERNAME=', line: 'DB_USERNAME=vagrant' } |
| 199 | + - { regexp: '^DB_PASSWORD=', line: 'DB_PASSWORD=vagrant' } |
| 200 | + - { regexp: '^APP_URL=', line: "APP_URL=http://{{ fqdn }}" } |
| 201 | + - { regexp: '^APP_ENV=', line: "APP_ENV=development" } |
| 202 | + - { regexp: '^APP_DEBUG=', line: "APP_ENV=true" } |
| 203 | + - name: Generate application key |
| 204 | + shell: "php {{ app_path }}/artisan key:generate --force" |
| 205 | + - name: Artisan Migrate |
| 206 | + shell: "php {{ app_path }}/artisan migrate --force" |
| 207 | + # |
| 208 | + # Create Cron Job |
| 209 | + # |
| 210 | + - name: Create scheduler cron job |
| 211 | + become: true |
| 212 | + cron: |
| 213 | + name: "Snipe-IT Artisan Scheduler" |
| 214 | + job: "/usr/bin/php {{ app_path }}/artisan schedule:run" |
| 215 | + handlers: |
| 216 | + - name: restart apache2 |
| 217 | + become: true |
| 218 | + systemd: |
| 219 | + name: apache2 |
| 220 | + state: restarted |
| 221 | + - name: restart mysql |
| 222 | + become: true |
| 223 | + systemd: |
| 224 | + name: mysql |
| 225 | + state: restarted |
| 226 | + |
0 commit comments