|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Create user |
| 4 | + user: |
| 5 | + name: "{{ vars_user }}" |
| 6 | + groups: docker |
| 7 | + append: true |
| 8 | + |
| 9 | +# -------------------- |
| 10 | + |
| 11 | +# Install Docker |
| 12 | + |
| 13 | +- name: Add Docker APT repository GPG key |
| 14 | + apt_key: |
| 15 | + state: present |
| 16 | + keyserver: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" |
| 17 | + id: 7EA0A9C3F273FCD8 |
| 18 | + |
| 19 | +- name: Add Docker APT repository |
| 20 | + apt_repository: |
| 21 | + repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable" |
| 22 | + state: present |
| 23 | + update_cache: true |
| 24 | + |
| 25 | +- name: Install Docker |
| 26 | + apt: |
| 27 | + name: docker-ce |
| 28 | + state: present |
| 29 | + notify: restart-docker |
| 30 | + |
| 31 | +- name: Make sure /etc/docker dir exists |
| 32 | + file: |
| 33 | + path: /etc/docker |
| 34 | + state: directory |
| 35 | + |
| 36 | +- name: Configure Docker daemon |
| 37 | + template: |
| 38 | + src: daemon.json |
| 39 | + dest: /etc/docker/daemon.json |
| 40 | + mode: 0600 |
| 41 | + notify: restart-docker |
| 42 | + |
| 43 | +# -------------------- |
| 44 | + |
| 45 | +# Set up a partition with limited space to avoid temporary |
| 46 | +# input/output files consuming all of the space on the primary |
| 47 | +# partition. |
| 48 | + |
| 49 | +- name: Check for mountpoint file |
| 50 | + stat: |
| 51 | + path: "{{ vars_mountpoint_file_path }}" |
| 52 | + register: mountpoint_stat |
| 53 | + |
| 54 | +- name: Create mountpoint file |
| 55 | + block: |
| 56 | + - name: Allocate file |
| 57 | + command: "fallocate -l {{ vars_mountpoint_size }} {{ vars_mountpoint_file_path }}" |
| 58 | + |
| 59 | + - name: Locate mountpoint loopback device |
| 60 | + command: "losetup -f --show {{ vars_mountpoint_file_path }}" |
| 61 | + register: loopback |
| 62 | + |
| 63 | + - name: Partition mountpoint |
| 64 | + command: "mkfs -t ext3 -m 1 -v {{ loopback.stdout }}" |
| 65 | + when: mountpoint_stat.stat.size is not defined or mountpoint_stat.stat.size != vars_mountpoint_size |
| 66 | + |
| 67 | +- name: Create mountpoint |
| 68 | + file: |
| 69 | + path: "{{ vars_mountpoint_path }}" |
| 70 | + state: directory |
| 71 | + |
| 72 | +- name: Mount mountpoint |
| 73 | + mount: |
| 74 | + src: "{{ vars_mountpoint_file_path }}" |
| 75 | + name: "{{ vars_mountpoint_path }}" |
| 76 | + fstype: ext3 |
| 77 | + state: mounted |
| 78 | + |
| 79 | +- name: Change kubeconfig file permission |
| 80 | + file: |
| 81 | + path: "{{ vars_mountpoint_path }}" |
| 82 | + owner: "{{ vars_user }}" |
| 83 | + group: docker |
| 84 | + |
| 85 | +# -------------------- |
| 86 | + |
| 87 | +- name: Checkout repository |
| 88 | + become: true |
| 89 | + become_user: "{{ vars_user }}" |
| 90 | + git: |
| 91 | + repo: "{{ vars_repository_url }}" |
| 92 | + dest: "{{ vars_checkout_path }}" |
| 93 | + version: "{{ vars_repository_sha }}" |
| 94 | + |
| 95 | +- name: Install awscli |
| 96 | + apt: |
| 97 | + name: awscli |
| 98 | + state: present |
| 99 | + |
| 100 | +- name: Allow user to start and stop service |
| 101 | + template: |
| 102 | + src: sudoers |
| 103 | + dest: "/etc/sudoers.d/{{ vars_user }}" |
| 104 | + mode: 0440 |
| 105 | + |
| 106 | +# --------- |
| 107 | + |
| 108 | +- name: install apt packages |
| 109 | + apt: |
| 110 | + name: |
| 111 | + - build-essential |
| 112 | + - cmake |
| 113 | + - libssl-dev |
| 114 | + - pkg-config |
| 115 | + state: present |
| 116 | + |
| 117 | +- name: check if cargo is installed |
| 118 | + shell: | |
| 119 | + test -f ~/.cargo/env && . ~/.cargo/env && command -v cargo |
| 120 | + register: cargo_exists |
| 121 | + ignore_errors: yes |
| 122 | + |
| 123 | +- name: Download Installer |
| 124 | + when: cargo_exists is failed |
| 125 | + get_url: |
| 126 | + url: https://sh.rustup.rs |
| 127 | + dest: /tmp/sh.rustup.rs |
| 128 | + mode: '0755' |
| 129 | + force: 'yes' |
| 130 | + |
| 131 | +- name: install rust/cargo |
| 132 | + when: cargo_exists is failed |
| 133 | + shell: /tmp/sh.rustup.rs -y |
| 134 | + |
| 135 | +- name: Build builder |
| 136 | + shell: | |
| 137 | + . ~/.cargo/env |
| 138 | + cargo build --release |
| 139 | + args: |
| 140 | + chdir: "{{ vars_checkout_path }}" |
| 141 | + |
| 142 | +- name: Configure service |
| 143 | + template: |
| 144 | + src: builder.service |
| 145 | + dest: /etc/systemd/system/builder.service |
| 146 | + mode: 0644 |
| 147 | + |
| 148 | +- name: Start and enable service |
| 149 | + systemd: |
| 150 | + name: builder |
| 151 | + state: started |
| 152 | + enabled: true |
0 commit comments