From e89a6d4e3d7e68cdc2ab95e8ca0257f564e5544b Mon Sep 17 00:00:00 2001 From: sergio Date: Fri, 18 Mar 2022 19:52:43 +0300 Subject: [PATCH] ansible enhancements (#18) Signed-off-by: Sergio Nemirowski --- handlers/main.yml | 2 +- tasks/binary.yml | 12 +++++ tasks/{download_cli.yml => cli.yml} | 0 tasks/healthcheck.yml | 1 - tasks/main.yml | 73 ++++++---------------------- tasks/{prepare_user.yml => user.yml} | 8 +-- tasks/wallet.yml | 11 +++++ 7 files changed, 42 insertions(+), 65 deletions(-) create mode 100644 tasks/binary.yml rename tasks/{download_cli.yml => cli.yml} (100%) rename tasks/{prepare_user.yml => user.yml} (77%) create mode 100644 tasks/wallet.yml diff --git a/handlers/main.yml b/handlers/main.yml index 77b787f..c303160 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,6 +1,6 @@ --- -- name: Restart neofs-ir instance service +- name: Restart NeoFS IR service ansible.builtin.systemd: name: "neofs-ir{{ neofs_ir__instance }}.service" state: 'restarted' diff --git a/tasks/binary.yml b/tasks/binary.yml new file mode 100644 index 0000000..87cecee --- /dev/null +++ b/tasks/binary.yml @@ -0,0 +1,12 @@ +--- + +- name: Download NeoFS IR binary + ansible.builtin.get_url: + url: "{{ neofs_ir__bin_url }}" + dest: "{{ neofs_ir__bin_path }}" + owner: 'root' + group: 'root' + mode: '0755' + when: not (neofs_ir__use_compose | bool) + notify: + - Restart NeoFS IR service diff --git a/tasks/download_cli.yml b/tasks/cli.yml similarity index 100% rename from tasks/download_cli.yml rename to tasks/cli.yml diff --git a/tasks/healthcheck.yml b/tasks/healthcheck.yml index 427c0e6..38b3ae4 100644 --- a/tasks/healthcheck.yml +++ b/tasks/healthcheck.yml @@ -15,4 +15,3 @@ until: _neofs_ir_check_result.rc == 0 retries: 10 delay: 30 - diff --git a/tasks/main.yml b/tasks/main.yml index 92e827d..17ee0f0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,17 +1,6 @@ --- -# Prepare system -- ansible.builtin.include: 'prepare_user.yml' - -- name: Ensure data directory exists - ansible.builtin.file: - state: directory - path: "{{ item }}" - owner: "{{ neofs_ir__user }}" - group: "{{ neofs_ir__group }}" - mode: '0750' - with_items: - - "{{ neofs_ir__data_dir }}" +- ansible.builtin.include_tasks: 'user.yml' - name: Create configuration directory parent ansible.builtin.file: @@ -33,15 +22,7 @@ with_items: - "{{ neofs_ir__conf_dir }}" -- name: Ensure there is node wallet - ansible.builtin.copy: - content: "{{ neofs_ir__wallet }}" - dest: "{{ neofs_ir__wallet_path }}" - owner: 'root' - group: "{{ neofs_ir__group }}" - mode: '0660' - notify: - - Restart neofs-ir instance service +- ansible.builtin.include_tasks: 'wallet.yml' - name: Download locode database archive ansible.builtin.unarchive: @@ -52,9 +33,9 @@ group: "{{ neofs_ir__group }}" mode: '0644' notify: - - Restart neofs-ir instance service + - Restart NeoFS IR service -- name: Prepare NeoFS IR config for neofs-ir{{ neofs_ir__instance }} +- name: Copy NeoFS IR config ansible.builtin.template: src: 'config.yaml.j2' dest: "{{ neofs_ir__conf_dir }}/config.yaml" @@ -62,32 +43,13 @@ group: "{{ neofs_ir__group }}" mode: '0640' notify: - - Restart neofs-ir instance service + - Restart NeoFS IR service -- name: Download neofs-ir binary - ansible.builtin.get_url: - url: "{{ neofs_ir__bin_url }}" - dest: "{{ neofs_ir__bin_path }}" - owner: 'root' - group: 'root' - mode: '0755' - when: not (neofs_ir__use_compose | bool) - notify: - - Restart neofs-ir instance service - -- include: download_cli.yml +- ansible.builtin.include_tasks: 'binary.yml' -- name: Get uid for neofs-ir user - ansible.builtin.getent: - database: passwd - key: "{{ neofs_ir__user }}" +- ansible.builtin.include_tasks: 'cli.yml' -- name: Get gid for neofs-ir user - ansible.builtin.getent: - database: group - key: "{{ neofs_ir__group }}" - -- name: Prepare docker-compose for neofs-ir{{ neofs_ir__instance }} +- name: Copy compose file ansible.builtin.template: src: 'docker-compose.yml.j2' dest: "{{ neofs_ir__conf_dir }}/docker-compose.yml" @@ -96,35 +58,28 @@ mode: '0640' when: neofs_ir__use_compose | bool notify: - - Restart neofs-ir instance service + - Restart NeoFS IR service -- name: Copy regular systemd unit file +- name: Copy regular systemd unit ansible.builtin.template: src: "neofs-ir.service.bin.j2" dest: "/etc/systemd/system/neofs-ir{{ neofs_ir__instance }}.service" when: not (neofs_ir__use_compose | bool) notify: - - Restart neofs-ir instance service + - Restart NeoFS IR service -- name: Copy Docker systemd unit file +- name: Copy dockerized systemd unit ansible.builtin.template: src: "neofs-ir.service.compose.j2" dest: "/etc/systemd/system/neofs-ir{{ neofs_ir__instance }}.service" when: neofs_ir__use_compose | bool notify: - - Restart neofs-ir instance service - -- name: Ensure NeoFS IR{{ neofs_ir__instance }} service runs - ansible.builtin.systemd: - name: "neofs-ir{{ neofs_ir__instance }}.service" - state: 'started' - enabled: yes - daemon_reload: yes + - Restart NeoFS IR service - include: healthcheck.yml - name: Force debops.ferm run - include_role: + ansible.builtin.include_role: name: debops.debops.ferm vars: ferm__dependent_rules: diff --git a/tasks/prepare_user.yml b/tasks/user.yml similarity index 77% rename from tasks/prepare_user.yml rename to tasks/user.yml index 68937c9..66eed1a 100644 --- a/tasks/prepare_user.yml +++ b/tasks/user.yml @@ -1,12 +1,12 @@ --- -- name: Ensure there is neofs-ir group +- name: Create NeoFS IR group ansible.builtin.group: name: "{{ neofs_ir__group }}" system: yes state: 'present' -- name: Ensure there is neofs-ir user +- name: Create NeoFS IR user ansible.builtin.user: name: "{{ neofs_ir__user }}" group: "{{ neofs_ir__group }}" @@ -17,12 +17,12 @@ skeleton: no state: 'present' -- name: Get uid for neofs-ir user +- name: Get UID for NeoFS IR user ansible.builtin.getent: database: passwd key: "{{ neofs_ir__user }}" -- name: Get gid for neofs-ir user +- name: Get GID for NeoFS IR user ansible.builtin.getent: database: group key: "{{ neofs_ir__group }}" diff --git a/tasks/wallet.yml b/tasks/wallet.yml new file mode 100644 index 0000000..67d3974 --- /dev/null +++ b/tasks/wallet.yml @@ -0,0 +1,11 @@ +--- + +- name: Copy wallet + ansible.builtin.copy: + content: "{{ neofs_ir__wallet }}" + dest: "{{ neofs_ir__wallet_path }}" + owner: 'root' + group: "{{ neofs_ir__group }}" + mode: '0660' + notify: + - Restart NeoFS IR service