From d58e90a18fc1b10cc28d36c7f81dc8248439e677 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:10:32 +0300 Subject: [PATCH 1/8] Add cleanup tag --- molecule/converge.yml | 10 +++++++++- roles/ccp/tasks/01-install.yml | 15 +++++++++++++-- roles/ccp/tasks/main.yml | 3 +++ roles/nox/tasks/01-install.yml | 21 ++++++++++++++++----- roles/nox/tasks/main.yml | 3 +++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/molecule/converge.yml b/molecule/converge.yml index f1c31b8..0f0b430 100644 --- a/molecule/converge.yml +++ b/molecule/converge.yml @@ -1,4 +1,4 @@ -- name: role +- name: All roles hosts: all become: true vars: @@ -38,3 +38,11 @@ - name: Run prometheus role include_role: name: prometheus + + - name: Run nox role + include_role: + name: nox + + - name: Run ccp role + include_role: + name: ccp diff --git a/roles/ccp/tasks/01-install.yml b/roles/ccp/tasks/01-install.yml index 502a459..ec18938 100644 --- a/roles/ccp/tasks/01-install.yml +++ b/roles/ccp/tasks/01-install.yml @@ -13,11 +13,21 @@ create_home: false state: present +- name: stop ccp + tags: + - never + - cleanup + ansible.builtin.systemd: + name: ccp + state: stopped + - name: cleanup ccp state + tags: + - never + - cleanup ansible.builtin.file: path: "{{ ccp_dir }}" state: absent - when: ccp_cleanup_state - name: create ccp directories ansible.builtin.file: @@ -128,8 +138,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/main.yml b/roles/ccp/tasks/main.yml index 08e8c0f..2723d51 100644 --- a/roles/ccp/tasks/main.yml +++ b/roles/ccp/tasks/main.yml @@ -3,4 +3,7 @@ ansible.builtin.include_tasks: 00-preflight.yml - name: Install CCP + tags: + - never + - cleanup ansible.builtin.include_tasks: 01-install.yml diff --git a/roles/nox/tasks/01-install.yml b/roles/nox/tasks/01-install.yml index f208e2a..d903739 100644 --- a/roles/nox/tasks/01-install.yml +++ b/roles/nox/tasks/01-install.yml @@ -13,23 +13,33 @@ create_home: false state: present +- name: stop nox + tags: + - never + - cleanup + ansible.builtin.systemd: + name: nox + state: stopped + - name: cleanup nox state + tags: + - never + - cleanup ansible.builtin.file: path: "{{ nox_dir }}" state: absent when: nox_cleanup_state - name: cleanup VMs if any + tags: + - never + - cleanup block: - name: List all VMs community.libvirt.virt: command: list_vms register: all_vms - - debug: - msg: "{{ item }}" - loop: "{{ all_vms.list_vms }}" - - name: "Destroy vm {{ item }}" community.libvirt.virt: name: "{{ item }}" @@ -157,8 +167,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/main.yml b/roles/nox/tasks/main.yml index d3db1b8..bf9d40e 100644 --- a/roles/nox/tasks/main.yml +++ b/roles/nox/tasks/main.yml @@ -3,4 +3,7 @@ ansible.builtin.include_tasks: 00-preflight.yml - name: Install Nox + tags: + - never + - cleanup ansible.builtin.include_tasks: 01-install.yml From a77f164da25d217aff63f3190f3c22a9ce7dbb6e Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:11:36 +0300 Subject: [PATCH 2/8] F --- molecule/converge.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/molecule/converge.yml b/molecule/converge.yml index 0f0b430..bf31b78 100644 --- a/molecule/converge.yml +++ b/molecule/converge.yml @@ -38,11 +38,3 @@ - name: Run prometheus role include_role: name: prometheus - - - name: Run nox role - include_role: - name: nox - - - name: Run ccp role - include_role: - name: ccp From 5ed35264dde7140082b9be58fc746f0b51b40290 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:17:48 +0300 Subject: [PATCH 3/8] Fix --- roles/ccp/tasks/main.yml | 1 - roles/nox/tasks/main.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/roles/ccp/tasks/main.yml b/roles/ccp/tasks/main.yml index 2723d51..d832905 100644 --- a/roles/ccp/tasks/main.yml +++ b/roles/ccp/tasks/main.yml @@ -4,6 +4,5 @@ - name: Install CCP tags: - - never - cleanup ansible.builtin.include_tasks: 01-install.yml diff --git a/roles/nox/tasks/main.yml b/roles/nox/tasks/main.yml index bf9d40e..a2331fb 100644 --- a/roles/nox/tasks/main.yml +++ b/roles/nox/tasks/main.yml @@ -4,6 +4,5 @@ - name: Install Nox tags: - - never - cleanup ansible.builtin.include_tasks: 01-install.yml From 8110b736fdbb1ffec17f44d17a964e5acb2aacc2 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:33:39 +0300 Subject: [PATCH 4/8] Update readme and fixes --- roles/ccp/README.md | 47 ++++++++++++++------------- roles/nox/README.md | 47 ++++++++++++++------------- roles/nox/tasks/01-install.yml | 2 -- roles/prometheus/README.md | 10 ++++-- roles/prometheus/tasks/01-install.yml | 18 +++++++++- roles/prometheus/tasks/main.yml | 2 +- roles/promtail/README.md | 8 +++-- roles/promtail/tasks/01-install.yml | 18 +++++++++- 8 files changed, 96 insertions(+), 56 deletions(-) diff --git a/roles/ccp/README.md b/roles/ccp/README.md index a3d4c30..301912a 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`: +Run playbook with tag `cleanup`: + ```bash -ansible-playbook ccp.yml -e "ccp_cleanup_state=true" +ansible-playbook ccp.yml --tags cleanup ``` ### Install ccp snapshot from PR @@ -21,7 +24,9 @@ ansible-playbook ccp.yml -e "ccp_branch=FLU-668" ## 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` @@ -47,9 +52,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 +62,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/nox/README.md b/roles/nox/README.md index 8957a9a..05bec80 100644 --- a/roles/nox/README.md +++ b/roles/nox/README.md @@ -9,9 +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 tag `cleanup`: + ```bash -ansible-playbook nox.yml -e "nox_cleanup_state=true" +ansible-playbook nox.yml --tags cleanup ``` ### Install nox snapshot from PR @@ -22,7 +23,9 @@ ansible-playbook nox.yml -e "nox_branch=FLU-688" ## Role Variables -See [defaults/](https://github.com/fluencelabs/ansible/blob/main/roles/nox/defaults) for details and examples. +See +[defaults/](https://github.com/fluencelabs/ansible/blob/main/roles/nox/defaults) +for details and examples. #### `fluence_project_dir` @@ -48,9 +51,9 @@ Should be put to `files/` directory where you run this role. - root nox directory - type: string - default: - ```yml - nox_dir: "/opt/fluence/nox" - ``` + ```yml + nox_dir: "/opt/fluence/nox" + ``` It will contain everything this role creates: nox binaries, configs, secrets. @@ -58,40 +61,38 @@ It will contain everything this role creates: nox binaries, configs, secrets. - systemd unit file - type: string -- default: see [defaults/main.yml](https://github.com/fluencelabs/blob/main/roles/nox/defaults/main.yml) +- default: see + [defaults/main.yml](https://github.com/fluencelabs/blob/main/roles/nox/defaults/main.yml) #### `nox_user` - owner of Nox process and files - type: string - default: - ```yml - nox_user: "nox" - ``` + ```yml + nox_user: "nox" + ``` #### `nox_group` - group of `nox_user` - type: string - default: - ```yml - nox_group: "nox" - ``` - -#### `nox_cleanup_state` - -- whether to cleanup nox state -- type: bool -- default: - ```yml - nox_cleanup_state: false - ``` + ```yml + nox_group: "nox" + ``` #### `nox_branch` -- whole catalogue of branches can be viewed here https://files.fluence.dev/buckets/fluence-artifacts + +- whole catalogue of branches can be viewed here + https://files.fluence.dev/buckets/fluence-artifacts - type: string +## Role Tags + +- `cleanup` - stop nox and cleanup state + ## Author - **Anatolios Laskaris** - [nahsi](https://github.com/nahsi) diff --git a/roles/nox/tasks/01-install.yml b/roles/nox/tasks/01-install.yml index d903739..824a414 100644 --- a/roles/nox/tasks/01-install.yml +++ b/roles/nox/tasks/01-install.yml @@ -28,7 +28,6 @@ ansible.builtin.file: path: "{{ nox_dir }}" state: absent - when: nox_cleanup_state - name: cleanup VMs if any tags: @@ -51,7 +50,6 @@ name: "{{ item }}" command: undefine loop: "{{ all_vms.list_vms }}" - when: nox_cleanup_state - name: create nox directories ansible.builtin.file: 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..215e65a 100644 --- a/roles/prometheus/tasks/01-install.yml +++ b/roles/prometheus/tasks/01-install.yml @@ -35,6 +35,22 @@ state: present when: fluence_prometheus_user != "root" +- name: stop prometheus + tags: + - never + - cleanup + ansible.builtin.systemd: + name: fluence-prometheus + state: stopped + +- name: cleanup prometheus state + tags: + - never + - cleanup + ansible.builtin.file: + path: "{{ fluence_prometheus_dir }}" + state: absent + - name: create prometheus directories ansible.builtin.file: path: "{{ fluence_prometheus_dir }}" @@ -78,7 +94,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/main.yml b/roles/prometheus/tasks/main.yml index 7abe3e7..fc61e54 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -3,5 +3,5 @@ include_tasks: 00-preflight.yml - name: Install prometheus - tags: configs + tags: cleanup include_tasks: 01-install.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..9189b74 100644 --- a/roles/promtail/tasks/01-install.yml +++ b/roles/promtail/tasks/01-install.yml @@ -37,6 +37,22 @@ state: present when: fluence_promtail_user != "root" +- name: stop promtail + tags: + - never + - cleanup + ansible.builtin.systemd: + name: fluence-promtail + state: stopped + +- name: cleanup promtail state + tags: + - never + - cleanup + ansible.builtin.file: + path: "{{ fluence_promtail_dir }}" + state: absent + - name: create promtail directories ansible.builtin.file: path: "{{ fluence_promtail_dir }}" @@ -80,7 +96,7 @@ mode: 0o755 notify: restart promtail -- name: enable promtail +- name: enable and start promtail ansible.builtin.systemd: name: fluence-promtail enabled: true From 7349835c8bf6cc983bd3fe241cd54e2ee4d3c4f3 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:34:31 +0300 Subject: [PATCH 5/8] Fix --- roles/ccp/defaults/main.yml | 1 - roles/nox/defaults/main.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/roles/ccp/defaults/main.yml b/roles/ccp/defaults/main.yml index 4ec7366..62bfce9 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 diff --git a/roles/nox/defaults/main.yml b/roles/nox/defaults/main.yml index 1274f64..832f0fc 100644 --- a/roles/nox/defaults/main.yml +++ b/roles/nox/defaults/main.yml @@ -4,7 +4,6 @@ nox_project_dir: "" nox_group: "nox" nox_user: "nox" nox_branch: "" -nox_cleanup_state: false nox_unit_file: | [Unit] Description=Nox - Rust implementation of the Fluence network peer From 9c10adc89279a33ec79e786b6e3569b40d1bb402 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Sat, 21 Sep 2024 12:45:44 +0300 Subject: [PATCH 6/8] Bye bye debian --- .github/workflows/ansible.yml | 1 - molecule/debian12/molecule.yml | 25 ------------------------- 2 files changed, 26 deletions(-) delete mode 100644 molecule/debian12/molecule.yml diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml index 4a4e016..457d48e 100644 --- a/.github/workflows/ansible.yml +++ b/.github/workflows/ansible.yml @@ -42,7 +42,6 @@ jobs: matrix: scenario: - ubuntu2204 - - debian12 steps: - uses: actions/checkout@v4 diff --git a/molecule/debian12/molecule.yml b/molecule/debian12/molecule.yml deleted file mode 100644 index 818d40d..0000000 --- a/molecule/debian12/molecule.yml +++ /dev/null @@ -1,25 +0,0 @@ -driver: - name: molecule-qemu - -platforms: - - name: debian12 - image_url: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bookworm/latest/SHA512SUMS - network_ssh_port: 2229 - -provisioner: - name: ansible - playbooks: - prepare: ../prepare.yml - converge: ../converge.yml - -verifier: - name: testinfra - directory: ../tests - env: - # get rid of the DeprecationWarning messages of third-party libs, - # see https://docs.pytest.org/en/latest/warnings.html#deprecationwarning-and-pendingdeprecationwarning - PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning" - options: - # show which tests where executed in test output - v: 1 From 4307ac693789df81655fa1537f949e64cd4fb79e Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Mon, 23 Sep 2024 15:48:37 +0300 Subject: [PATCH 7/8] Update --- roles/ccp/README.md | 7 +++- roles/ccp/defaults/main.yml | 4 +++ roles/ccp/tasks/01-install.yml | 23 +++++-------- roles/ccp/tasks/02-uninstall.yml | 16 +++++++++ roles/ccp/tasks/main.yml | 7 ++-- roles/ipfs_cli/tasks/00-preflight.yml | 9 ----- roles/ipfs_cli/tasks/01-ipfs.yml | 6 ---- roles/nox/README.md | 7 +++- roles/nox/defaults/main.yml | 3 ++ roles/nox/tasks/01-install.yml | 44 ++++--------------------- roles/nox/tasks/02-uninstall.yml | 38 +++++++++++++++++++++ roles/nox/tasks/main.yml | 7 ++-- roles/prometheus/tasks/01-install.yml | 16 --------- roles/prometheus/tasks/02-uninstall.yml | 17 ++++++++++ roles/prometheus/tasks/main.yml | 6 +++- roles/promtail/tasks/01-install.yml | 16 --------- roles/promtail/tasks/02-uninstall.yml | 16 +++++++++ roles/promtail/tasks/main.yml | 6 +++- 18 files changed, 141 insertions(+), 107 deletions(-) create mode 100644 roles/ccp/tasks/02-uninstall.yml create mode 100644 roles/nox/tasks/02-uninstall.yml create mode 100644 roles/prometheus/tasks/02-uninstall.yml create mode 100644 roles/promtail/tasks/02-uninstall.yml diff --git a/roles/ccp/README.md b/roles/ccp/README.md index 301912a..ba22f04 100644 --- a/roles/ccp/README.md +++ b/roles/ccp/README.md @@ -40,7 +40,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` diff --git a/roles/ccp/defaults/main.yml b/roles/ccp/defaults/main.yml index 62bfce9..5b65185 100644 --- a/roles/ccp/defaults/main.yml +++ b/roles/ccp/defaults/main.yml @@ -18,3 +18,7 @@ ccp_unit_file: | [Install] WantedBy=multi-user.target + +fluence_cleanup: false +ccp_cleanup: "{{ false | default(fluence_cleanup) }}" +ccp_cleanup_state: "{{ ccp_cleanup }}" diff --git a/roles/ccp/tasks/01-install.yml b/roles/ccp/tasks/01-install.yml index ec18938..feaa360 100644 --- a/roles/ccp/tasks/01-install.yml +++ b/roles/ccp/tasks/01-install.yml @@ -13,21 +13,14 @@ create_home: false state: present -- name: stop ccp - tags: - - never - - cleanup - ansible.builtin.systemd: - name: ccp - state: stopped - -- name: cleanup ccp state - tags: - - never - - cleanup - ansible.builtin.file: - path: "{{ ccp_dir }}" - state: absent +- name: cleanup ccp + when: + - ccp_cleanup == true + ansible.builtin.include_tasks: + file: 02-uninstall.yml + apply: + tags: + - uninstall - name: create ccp directories ansible.builtin.file: 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 d832905..51b5652 100644 --- a/roles/ccp/tasks/main.yml +++ b/roles/ccp/tasks/main.yml @@ -3,6 +3,9 @@ ansible.builtin.include_tasks: 00-preflight.yml - name: Install CCP - tags: - - cleanup 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 05bec80..06323ae 100644 --- a/roles/nox/README.md +++ b/roles/nox/README.md @@ -41,6 +41,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 @@ -91,7 +96,7 @@ It will contain everything this role creates: nox binaries, configs, secrets. ## Role Tags -- `cleanup` - stop nox and cleanup state +- `uninstall` - stop nox and delete nox directory ## Author diff --git a/roles/nox/defaults/main.yml b/roles/nox/defaults/main.yml index 832f0fc..19bf892 100644 --- a/roles/nox/defaults/main.yml +++ b/roles/nox/defaults/main.yml @@ -23,3 +23,6 @@ nox_unit_file: | [Install] WantedBy=multi-user.target +fluence_cleanup: false +nox_cleanup: "{{ false | default(fluence_cleanup) }}" +nox_cleanup_state: "{{ nox_cleanup }}" diff --git a/roles/nox/tasks/01-install.yml b/roles/nox/tasks/01-install.yml index 824a414..ab4ea5b 100644 --- a/roles/nox/tasks/01-install.yml +++ b/roles/nox/tasks/01-install.yml @@ -13,43 +13,13 @@ create_home: false state: present -- name: stop nox - tags: - - never - - cleanup - ansible.builtin.systemd: - name: nox - state: stopped - -- name: cleanup nox state - tags: - - never - - cleanup - ansible.builtin.file: - path: "{{ nox_dir }}" - state: absent - -- name: cleanup VMs if any - tags: - - never - - cleanup - 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 }}" +- name: cleanup Nox + when: nox_cleanup == true + ansible.builtin.include_tasks: + file: 02-uninstall.yml + apply: + tags: + - uninstall - name: create nox directories ansible.builtin.file: 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 a2331fb..ac29fab 100644 --- a/roles/nox/tasks/main.yml +++ b/roles/nox/tasks/main.yml @@ -3,6 +3,9 @@ ansible.builtin.include_tasks: 00-preflight.yml - name: Install Nox - tags: - - cleanup ansible.builtin.include_tasks: 01-install.yml + +- name: Uninstall Nox + tags: + - uninstall + ansible.builtin.include_tasks: 02-uninstall.yml diff --git a/roles/prometheus/tasks/01-install.yml b/roles/prometheus/tasks/01-install.yml index 215e65a..4451eae 100644 --- a/roles/prometheus/tasks/01-install.yml +++ b/roles/prometheus/tasks/01-install.yml @@ -35,22 +35,6 @@ state: present when: fluence_prometheus_user != "root" -- name: stop prometheus - tags: - - never - - cleanup - ansible.builtin.systemd: - name: fluence-prometheus - state: stopped - -- name: cleanup prometheus state - tags: - - never - - cleanup - ansible.builtin.file: - path: "{{ fluence_prometheus_dir }}" - state: absent - - name: create prometheus directories ansible.builtin.file: path: "{{ fluence_prometheus_dir }}" 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 fc61e54..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: cleanup include_tasks: 01-install.yml + +- name: Uninstall prometheus + tags: + - uninstall + include_tasks: 02-uninstall.yml diff --git a/roles/promtail/tasks/01-install.yml b/roles/promtail/tasks/01-install.yml index 9189b74..4dcbdfe 100644 --- a/roles/promtail/tasks/01-install.yml +++ b/roles/promtail/tasks/01-install.yml @@ -37,22 +37,6 @@ state: present when: fluence_promtail_user != "root" -- name: stop promtail - tags: - - never - - cleanup - ansible.builtin.systemd: - name: fluence-promtail - state: stopped - -- name: cleanup promtail state - tags: - - never - - cleanup - ansible.builtin.file: - path: "{{ fluence_promtail_dir }}" - state: absent - - name: create promtail directories ansible.builtin.file: path: "{{ fluence_promtail_dir }}" 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 From 540d599e678783e41ae4ae682f751c2aac0dc972 Mon Sep 17 00:00:00 2001 From: Anatoly Laskaris Date: Mon, 23 Sep 2024 15:56:28 +0300 Subject: [PATCH 8/8] Update --- roles/ccp/README.md | 12 ++++++++++-- roles/ccp/defaults/main.yml | 2 +- roles/ccp/tasks/01-install.yml | 2 +- roles/nox/README.md | 12 ++++++++++-- roles/nox/defaults/main.yml | 2 +- roles/nox/tasks/01-install.yml | 2 +- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/roles/ccp/README.md b/roles/ccp/README.md index ba22f04..97d1b38 100644 --- a/roles/ccp/README.md +++ b/roles/ccp/README.md @@ -10,10 +10,10 @@ See this [example](https://github.com/fluencelabs/ansible/blob/main/example/) ### Cleanup ccp state -Run playbook with tag `cleanup`: +Rerun playbook with flag `ccp_cleanup` set to `true`: ```bash -ansible-playbook ccp.yml --tags cleanup +ansible-playbook ccp.yml -e ccp_cleanup=true ``` ### Install ccp snapshot from PR @@ -22,6 +22,14 @@ ansible-playbook ccp.yml --tags cleanup 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 diff --git a/roles/ccp/defaults/main.yml b/roles/ccp/defaults/main.yml index 5b65185..514c971 100644 --- a/roles/ccp/defaults/main.yml +++ b/roles/ccp/defaults/main.yml @@ -21,4 +21,4 @@ ccp_unit_file: | fluence_cleanup: false ccp_cleanup: "{{ false | default(fluence_cleanup) }}" -ccp_cleanup_state: "{{ ccp_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 feaa360..1c79848 100644 --- a/roles/ccp/tasks/01-install.yml +++ b/roles/ccp/tasks/01-install.yml @@ -15,7 +15,7 @@ - name: cleanup ccp when: - - ccp_cleanup == true + - ccp_cleanup_state == true ansible.builtin.include_tasks: file: 02-uninstall.yml apply: diff --git a/roles/nox/README.md b/roles/nox/README.md index 06323ae..d258a07 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 tag `cleanup`: +Rerun playbook with flag `nox_cleanup` set to `true`: ```bash -ansible-playbook nox.yml --tags cleanup +ansible-playbook nox.yml -e nox_cleanup=true ``` ### Install nox snapshot from PR @@ -21,6 +21,14 @@ ansible-playbook nox.yml --tags cleanup 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 diff --git a/roles/nox/defaults/main.yml b/roles/nox/defaults/main.yml index 19bf892..8e47d3d 100644 --- a/roles/nox/defaults/main.yml +++ b/roles/nox/defaults/main.yml @@ -25,4 +25,4 @@ nox_unit_file: | fluence_cleanup: false nox_cleanup: "{{ false | default(fluence_cleanup) }}" -nox_cleanup_state: "{{ nox_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 ab4ea5b..7d448ce 100644 --- a/roles/nox/tasks/01-install.yml +++ b/roles/nox/tasks/01-install.yml @@ -14,7 +14,7 @@ state: present - name: cleanup Nox - when: nox_cleanup == true + when: nox_cleanup_state == true ansible.builtin.include_tasks: file: 02-uninstall.yml apply: