diff --git a/molecule/converge.yml b/molecule/converge.yml index f1c31b8..bf31b78 100644 --- a/molecule/converge.yml +++ b/molecule/converge.yml @@ -1,4 +1,4 @@ -- name: role +- name: All roles hosts: all become: true vars: diff --git a/roles/ccp/README.md b/roles/ccp/README.md index a3d4c30..97d1b38 100644 --- a/roles/ccp/README.md +++ b/roles/ccp/README.md @@ -1,6 +1,8 @@ # fluencelabs.provider.ccp -Install and configure [ccp](https://github.com/fluencelabs/capacity-commitment-peer/) - Fluence capacity-commitment-prover +Install and configure +[ccp](https://github.com/fluencelabs/capacity-commitment-peer/) - Fluence +capacity-commitment-prover ## Usage @@ -8,9 +10,10 @@ See this [example](https://github.com/fluencelabs/ansible/blob/main/example/) ### Cleanup ccp state -Rerun playbook with `ccp_cleanup_state` set to `true`: +Rerun playbook with flag `ccp_cleanup` set to `true`: + ```bash -ansible-playbook ccp.yml -e "ccp_cleanup_state=true" +ansible-playbook ccp.yml -e ccp_cleanup=true ``` ### Install ccp snapshot from PR @@ -19,9 +22,19 @@ ansible-playbook ccp.yml -e "ccp_cleanup_state=true" ansible-playbook ccp.yml -e "ccp_branch=FLU-668" ``` +### Uninstall ccp + +Run role with tag `uninstall`: + +```bash +ansible-playbook ccp.yml --tags uninstall +``` + ## Role Variables -See [defaults/](https://github.com/fluencelabs/ansible/blob/main/roles/ccp/defaults) for details and examples. +See +[defaults/](https://github.com/fluencelabs/ansible/blob/main/roles/ccp/defaults) +for details and examples. #### `fluence_project_dir` @@ -35,7 +48,12 @@ Should be put to `files/` directory where you run this role. #### `fluence_instance_id` - instance id to assing to target. Shared in collection. -- type: stiring +- type: string + +#### `fluence_cleanup` or `ccp_cleanup` + +- Cleanup ccp state and restart ccp. +- type: bool #### `ccp_version` @@ -47,9 +65,9 @@ Should be put to `files/` directory where you run this role. - root ccp directory - type: string - default: - ```yml - ccp_dir: "/opt/fluence/ccp" - ``` + ```yml + ccp_dir: "/opt/fluence/ccp" + ``` It will contain everything this role creates: ccp binaries, configs and state. @@ -57,39 +75,35 @@ It will contain everything this role creates: ccp binaries, configs and state. - systemd unit file - type: string -- default: see [defaults/main.yml](https://github.com/fluencelabs/blob/main/roles/ccp/defaults/main.yml) +- default: see + [defaults/main.yml](https://github.com/fluencelabs/blob/main/roles/ccp/defaults/main.yml) #### `ccp_user` - owner of ccp process and files - type: string - default: - ```yml - ccp_user: "ccp" - ``` + ```yml + ccp_user: "ccp" + ``` #### `ccp_group` - group of `ccp_user` - type: string - default: - ```yml - ccp_group: "ccp" - ``` - -#### `ccp_cleanup_state` - -- whether to cleanup ccp state -- type: bool -- default: - ```yml - ccp_cleanup_state: false - ``` + ```yml + ccp_group: "ccp" + ``` #### `ccp_branch` - type: string +## Role Tags + +- `cleanup` - stop ccp and cleanup state + ## Author - **Anatolios Laskaris** - [nahsi](https://github.com/nahsi) diff --git a/roles/ccp/defaults/main.yml b/roles/ccp/defaults/main.yml index 4ec7366..514c971 100644 --- a/roles/ccp/defaults/main.yml +++ b/roles/ccp/defaults/main.yml @@ -4,7 +4,6 @@ ccp_project_dir: "" ccp_group: "ccp" ccp_user: "ccp" ccp_branch: "" -ccp_cleanup_state: false ccp_unit_file: | [Unit] Description=CCP - Fluence capacity commitment prover @@ -19,3 +18,7 @@ ccp_unit_file: | [Install] WantedBy=multi-user.target + +fluence_cleanup: false +ccp_cleanup: "{{ false | default(fluence_cleanup) }}" +ccp_cleanup_state: "{{ false | default(ccp_cleanup) }}" diff --git a/roles/ccp/tasks/01-install.yml b/roles/ccp/tasks/01-install.yml index 502a459..1c79848 100644 --- a/roles/ccp/tasks/01-install.yml +++ b/roles/ccp/tasks/01-install.yml @@ -13,11 +13,14 @@ create_home: false state: present -- name: cleanup ccp state - ansible.builtin.file: - path: "{{ ccp_dir }}" - state: absent - when: ccp_cleanup_state +- name: cleanup ccp + when: + - ccp_cleanup_state == true + ansible.builtin.include_tasks: + file: 02-uninstall.yml + apply: + tags: + - uninstall - name: create ccp directories ansible.builtin.file: @@ -128,8 +131,9 @@ mode: 0o755 notify: restart ccp -- name: enable ccp +- name: enable and start ccp ansible.builtin.systemd: name: ccp enabled: true daemon_reload: true + state: started diff --git a/roles/ccp/tasks/02-uninstall.yml b/roles/ccp/tasks/02-uninstall.yml new file mode 100644 index 0000000..afd9548 --- /dev/null +++ b/roles/ccp/tasks/02-uninstall.yml @@ -0,0 +1,16 @@ +- name: stop ccp + tags: + - never + - uninstall + ansible.builtin.systemd: + name: ccp + state: stopped + enabled: false + +- name: delete ccp directory + tags: + - never + - uninstall + ansible.builtin.file: + path: "{{ ccp_dir }}" + state: absent diff --git a/roles/ccp/tasks/main.yml b/roles/ccp/tasks/main.yml index 08e8c0f..51b5652 100644 --- a/roles/ccp/tasks/main.yml +++ b/roles/ccp/tasks/main.yml @@ -4,3 +4,8 @@ - name: Install CCP ansible.builtin.include_tasks: 01-install.yml + +- name: Uninstall CCP + tags: + - uninstall + ansible.builtin.include_tasks: 02-uninstall.yml diff --git a/roles/ipfs_cli/tasks/00-preflight.yml b/roles/ipfs_cli/tasks/00-preflight.yml index a52d7bb..17ee41f 100644 --- a/roles/ipfs_cli/tasks/00-preflight.yml +++ b/roles/ipfs_cli/tasks/00-preflight.yml @@ -8,15 +8,6 @@ - ipfs_cli_version is regex(_semver_regex) quiet: true -- name: check "nox_dir" variable - tags: always - ansible.builtin.assert: - that: - - nox_dir is defined - - nox_dir is string - - nox_dir | length - quiet: true - - name: check that tar is GNU type # noqa tags: always fluencelabs.provider.check_tar_type: diff --git a/roles/ipfs_cli/tasks/01-ipfs.yml b/roles/ipfs_cli/tasks/01-ipfs.yml index cae36f1..fd14671 100644 --- a/roles/ipfs_cli/tasks/01-ipfs.yml +++ b/roles/ipfs_cli/tasks/01-ipfs.yml @@ -28,12 +28,6 @@ - "--strip-components=1" - "kubo/ipfs" -- name: create "nox_dir" - ansible.builtin.file: - path: "{{ nox_dir }}" - state: directory - mode: 0o755 - - name: propagate IPFS binary ansible.builtin.copy: src: "{{ role_path }}/files/ipfs/{{ _ipfs_version }}/{{ _arch }}/ipfs" diff --git a/roles/nox/README.md b/roles/nox/README.md index 73aa520..66ed130 100644 --- a/roles/nox/README.md +++ b/roles/nox/README.md @@ -9,10 +9,10 @@ See this [example](https://github.com/fluencelabs/ansible/blob/main/example/) ### Cleanup nox state -Rerun playbook with `nox_cleanup_state` set to `true`: +Rerun playbook with flag `nox_cleanup` set to `true`: ```bash -ansible-playbook nox.yml -e "nox_cleanup_state=true" +ansible-playbook nox.yml -e nox_cleanup=true ``` ### Install nox snapshot from PR @@ -21,6 +21,14 @@ ansible-playbook nox.yml -e "nox_cleanup_state=true" ansible-playbook nox.yml -e "nox_branch=FLU-688" ``` +### Uninstall nox + +Run role with tag `uninstall`: + +```bash +ansible-playbook nox.yml --tags uninstall +``` + ## Role Variables See @@ -41,6 +49,11 @@ Should be put to `files/` directory where you run this role. - instance id to assing to target. Shared in collection. - type: string +#### `fluence_cleanup` or `nox_cleanup` + +- Cleanup nox state and restart nox. +- type: bool + #### `nox_version` - version of nox @@ -102,15 +115,6 @@ nox_local_backup_dir: "files/{{ fluence_project_dir }}/backups" nox_group: "nox" ``` -#### `nox_cleanup_state` - -- whether to cleanup nox state -- type: bool -- default: - ```yml - nox_cleanup_state: false - ``` - #### `nox_branch` - whole catalogue of branches can be viewed here @@ -118,6 +122,10 @@ nox_local_backup_dir: "files/{{ fluence_project_dir }}/backups" - type: string +## Role Tags + +- `uninstall` - stop nox and delete nox directory + ## Author - **Anatolios Laskaris** - [nahsi](https://github.com/nahsi) diff --git a/roles/nox/defaults/main.yml b/roles/nox/defaults/main.yml index 809bc02..4c02eb5 100644 --- a/roles/nox/defaults/main.yml +++ b/roles/nox/defaults/main.yml @@ -5,7 +5,6 @@ nox_group: "nox" nox_user: "nox" nox_log_level: "info" nox_branch: "" -nox_cleanup_state: false nox_local_backup_dir: "files/{{ fluence_project_dir }}/backups" nox_unit_file: | [Unit] @@ -26,3 +25,6 @@ nox_unit_file: | [Install] WantedBy=multi-user.target +fluence_cleanup: false +nox_cleanup: "{{ false | default(fluence_cleanup) }}" +nox_cleanup_state: "{{ false | default(nox_cleanup) }}" diff --git a/roles/nox/tasks/01-install.yml b/roles/nox/tasks/01-install.yml index df772e6..d737876 100644 --- a/roles/nox/tasks/01-install.yml +++ b/roles/nox/tasks/01-install.yml @@ -23,6 +23,14 @@ create_home: false state: present +- name: cleanup Nox + when: nox_cleanup_state == true + ansible.builtin.include_tasks: + file: 02-uninstall.yml + apply: + tags: + - uninstall + - name: add nox user to libvirt group ansible.builtin.user: name: "libvirt-qemu" @@ -194,8 +202,9 @@ group: root mode: 0o755 -- name: enable noxes +- name: enable and start nox ansible.builtin.systemd: name: nox enabled: true daemon_reload: true + state: started diff --git a/roles/nox/tasks/02-uninstall.yml b/roles/nox/tasks/02-uninstall.yml new file mode 100644 index 0000000..b581209 --- /dev/null +++ b/roles/nox/tasks/02-uninstall.yml @@ -0,0 +1,38 @@ +- name: stop nox + tags: + - never + - uninstall + ansible.builtin.systemd: + name: nox + state: stopped + enabled: false + +- name: delete nox directory + tags: + - never + - uninstall + ansible.builtin.file: + path: "{{ nox_dir }}" + state: absent + +- name: cleanup VMs if any + tags: + - never + - uninstall + block: + - name: List all VMs + community.libvirt.virt: + command: list_vms + register: all_vms + + - name: "Destroy vm {{ item }}" + community.libvirt.virt: + name: "{{ item }}" + command: destroy + loop: "{{ all_vms.list_vms }}" + + - name: "Undefine vm {{ item }}" + community.libvirt.virt: + name: "{{ item }}" + command: undefine + loop: "{{ all_vms.list_vms }}" diff --git a/roles/nox/tasks/main.yml b/roles/nox/tasks/main.yml index d3db1b8..ac29fab 100644 --- a/roles/nox/tasks/main.yml +++ b/roles/nox/tasks/main.yml @@ -4,3 +4,8 @@ - name: Install Nox ansible.builtin.include_tasks: 01-install.yml + +- name: Uninstall Nox + tags: + - uninstall + ansible.builtin.include_tasks: 02-uninstall.yml diff --git a/roles/prometheus/README.md b/roles/prometheus/README.md index 929f407..b27248e 100644 --- a/roles/prometheus/README.md +++ b/roles/prometheus/README.md @@ -1,9 +1,9 @@ # Fluence prometheus -Install, configure and maintain -[prometheus](https://prometheus.io) +Install, configure and maintain [prometheus](https://prometheus.io) -You need to get `fluence_basicauth_username` and `fluence_basicauth_password` from Cloudless Labs in order to use this role. +You need to get `fluence_basicauth_username` and `fluence_basicauth_password` +from Cloudless Labs in order to use this role. ## Role Variables @@ -76,6 +76,10 @@ for details and examples. [defaults/main.yml](https://github.com/fluencelabs/ansible/blob/main/roles/prometheus/defaults/main.yml) - type: string +## Role Tags + +- `cleanup` - stop and cleanup state + ## Author - **Anatolios Laskaris** - [nahsi](https://github.com/nahsi) diff --git a/roles/prometheus/tasks/01-install.yml b/roles/prometheus/tasks/01-install.yml index 5b0eacd..4451eae 100644 --- a/roles/prometheus/tasks/01-install.yml +++ b/roles/prometheus/tasks/01-install.yml @@ -78,7 +78,7 @@ mode: 0o755 notify: restart prometheus -- name: enable prometheus +- name: enable and start prometheus ansible.builtin.systemd: name: fluence-prometheus enabled: true diff --git a/roles/prometheus/tasks/02-uninstall.yml b/roles/prometheus/tasks/02-uninstall.yml new file mode 100644 index 0000000..7546a2e --- /dev/null +++ b/roles/prometheus/tasks/02-uninstall.yml @@ -0,0 +1,17 @@ +- name: stop prometheus + tags: + - never + - uninstall + ansible.builtin.systemd: + name: fluence-prometheus + state: stopped + enabled: false + +- name: delete prometheus directory + tags: + - never + - uninstall + ansible.builtin.file: + path: "{{ fluence_prometheus_dir }}" + state: absent + diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 7abe3e7..8613c51 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -3,5 +3,9 @@ include_tasks: 00-preflight.yml - name: Install prometheus - tags: configs include_tasks: 01-install.yml + +- name: Uninstall prometheus + tags: + - uninstall + include_tasks: 02-uninstall.yml diff --git a/roles/promtail/README.md b/roles/promtail/README.md index 831fee8..0c1328f 100644 --- a/roles/promtail/README.md +++ b/roles/promtail/README.md @@ -6,8 +6,8 @@ Install, configure and maintain Promtail instance by default will collect only Nox and CCP logs. But you can change config to anything you want. -You need to get `fluence_basicauth_username` and `fluence_basicauth_password` from -Cloudless Labs in order to use this role. +You need to get `fluence_basicauth_username` and `fluence_basicauth_password` +from Cloudless Labs in order to use this role. ## Role Variables @@ -85,6 +85,10 @@ for details and examples. - skip restart/reload - useful when building images with Packer - default: `false` +## Role Tags + +- `cleanup` - stop and cleanup state + ## Author - **Anatolios Laskaris** - [nahsi](https://github.com/nahsi) diff --git a/roles/promtail/tasks/01-install.yml b/roles/promtail/tasks/01-install.yml index 8e2c0b8..4dcbdfe 100644 --- a/roles/promtail/tasks/01-install.yml +++ b/roles/promtail/tasks/01-install.yml @@ -80,7 +80,7 @@ mode: 0o755 notify: restart promtail -- name: enable promtail +- name: enable and start promtail ansible.builtin.systemd: name: fluence-promtail enabled: true diff --git a/roles/promtail/tasks/02-uninstall.yml b/roles/promtail/tasks/02-uninstall.yml new file mode 100644 index 0000000..9d6ffd8 --- /dev/null +++ b/roles/promtail/tasks/02-uninstall.yml @@ -0,0 +1,16 @@ +- name: stop promtail + tags: + - never + - uninstall + ansible.builtin.systemd: + name: fluence-promtail + state: stopped + enabled: false + +- name: delete promtail directory + tags: + - never + - uninstall + ansible.builtin.file: + path: "{{ fluence_promtail_dir }}" + state: absent diff --git a/roles/promtail/tasks/main.yml b/roles/promtail/tasks/main.yml index e41b12f..8a5c36a 100644 --- a/roles/promtail/tasks/main.yml +++ b/roles/promtail/tasks/main.yml @@ -3,5 +3,9 @@ include_tasks: 00-preflight.yml - name: Install promtail - tags: configs include_tasks: 01-install.yml + +- name: Uninstall promtail + tags: + - uninstall + include_tasks: 02-uninstall.yml