Skip to content

Commit

Permalink
feat: Add uninstall tag and rename cleanup flags (#58)
Browse files Browse the repository at this point in the history
* Add cleanup tag

* F

* Fix

* Update readme and fixes

* Fix

* Bye bye debian

* Update

* Update
  • Loading branch information
nahsi authored Nov 4, 2024
1 parent 7f43136 commit a9faa3e
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 69 deletions.
2 changes: 1 addition & 1 deletion molecule/converge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: role
- name: All roles
hosts: all
become: true
vars:
Expand Down
62 changes: 38 additions & 24 deletions roles/ccp/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# 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

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
Expand All @@ -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`

Expand All @@ -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`

Expand All @@ -47,49 +65,45 @@ 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.
#### `ccp_unit_file`

- 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)
5 changes: 4 additions & 1 deletion roles/ccp/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }}"
16 changes: 10 additions & 6 deletions roles/ccp/tasks/01-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions roles/ccp/tasks/02-uninstall.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions roles/ccp/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions roles/ipfs_cli/tasks/00-preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
6 changes: 0 additions & 6 deletions roles/ipfs_cli/tasks/01-ipfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 19 additions & 11 deletions roles/nox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -102,22 +115,17 @@ 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
https://files.fluence.dev/buckets/fluence-artifacts

- type: string

## Role Tags

- `uninstall` - stop nox and delete nox directory

## Author

- **Anatolios Laskaris** - [nahsi](https://github.com/nahsi)
4 changes: 3 additions & 1 deletion roles/nox/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) }}"
11 changes: 10 additions & 1 deletion roles/nox/tasks/01-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
38 changes: 38 additions & 0 deletions roles/nox/tasks/02-uninstall.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
5 changes: 5 additions & 0 deletions roles/nox/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit a9faa3e

Please sign in to comment.