|
| 1 | +--- |
| 2 | +# Bare provisioning of a new server. |
| 3 | +# Use this command to execute: |
| 4 | +# |
| 5 | +# cd /home/controller/ce-provision && \ |
| 6 | +# ./scripts/provision.sh --workspace /home/controller/ce-provision \ |
| 7 | +# --repo none --branch none \ |
| 8 | +# --playbook /home/controller/ce-provision/plays/launcher/configure.yml \ |
| 9 | +# --ansible-extra-vars "_provision_host=X.X.X.X" |
| 10 | +# |
| 11 | +# Replace X.X.X.X with your hostname or IP address. |
| 12 | +- hosts: localhost |
| 13 | + vars: |
| 14 | + _ce_provision_username: controller |
| 15 | + _add_host: true # set to false if you do not want to add the new server to hosts.yml |
| 16 | + _ce_provision_config_branch: 2.x # change this if you didn't use our example config and have a different main branch name |
| 17 | + tasks: |
| 18 | + - name: Add the server to Ansible hosts in memory. |
| 19 | + ansible.builtin.add_host: |
| 20 | + hostname: "{{ _provision_host }}" |
| 21 | + |
| 22 | + - name: Add the server to hosts.yml. |
| 23 | + when: _add_host |
| 24 | + block: |
| 25 | + - name: Edit hosts.yml file. |
| 26 | + ansible.builtin.lineinfile: |
| 27 | + path: "/home/{{ _ce_provision_username }}/ce-provision/config/hosts/hosts.yml" |
| 28 | + line: "{{ _provision_host }}:" |
| 29 | + create: true |
| 30 | + |
| 31 | + - name: Add hosts.yml changes. |
| 32 | + ansible.builtin.command: git add . |
| 33 | + args: |
| 34 | + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" |
| 35 | + |
| 36 | + - name: Commit hosts.yml changes. |
| 37 | + ansible.builtin.shell: "git diff --staged --quiet || git commit -m 'Ansible autogenerated - host {{ _provision_host }} added.'" |
| 38 | + args: |
| 39 | + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" |
| 40 | + |
| 41 | + - name: Push the hosts file change to the config repository. |
| 42 | + ansible.builtin.command: "git push origin {{ _ce_provision_config_branch | default('main') }}" |
| 43 | + args: |
| 44 | + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" |
| 45 | + |
| 46 | +- hosts: "{{ _provision_host }}" |
| 47 | + vars: |
| 48 | + ansible_user: admin |
| 49 | + _ce_provision_build_id: 0 |
| 50 | + become: true |
| 51 | + tasks: |
| 52 | + - ansible.builtin.import_role: |
| 53 | + name: _init |
| 54 | + - ansible.builtin.import_role: |
| 55 | + name: debian/user_provision |
| 56 | + - ansible.builtin.import_role: |
| 57 | + name: _exit |
0 commit comments