From e5111c152ed0f8be09e3945d5f85ac2dca953c41 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:33:13 +0100 Subject: [PATCH 1/7] build: Add Github Action to lint Ansible playbooks Should test all pushes and pull requests --- .github/workflows/ansible-lint.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/ansible-lint.yml diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml new file mode 100644 index 0000000..047203c --- /dev/null +++ b/.github/workflows/ansible-lint.yml @@ -0,0 +1,21 @@ +name: Ansible Lint +on: + - pull_request + - push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Lint Ansible playbooks + # Lastest commit, as of 30 Apr 2020 + uses: ansible/ansible-lint-action@6c8c141 + with: + targets: | + scripts/ansible/kill_playbook.yml + scripts/ansible/ping_playbook.yml + scripts/ansible/restart_playbook.yml + scripts/ansible/update_playbook.yml From f5d3142bea2a64b7ae1c0506f76cbc9345024b1b Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:54:09 +0100 Subject: [PATCH 2/7] build: Add ansible-lint exceptions for pre-existing lint --- .github/workflows/ansible-lint.yml | 3 +++ scripts/ansible/.ansible-lint | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 scripts/ansible/.ansible-lint diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml index 047203c..3f4aff2 100644 --- a/.github/workflows/ansible-lint.yml +++ b/.github/workflows/ansible-lint.yml @@ -19,3 +19,6 @@ jobs: scripts/ansible/ping_playbook.yml scripts/ansible/restart_playbook.yml scripts/ansible/update_playbook.yml + + args: + -c scripts/ansible/.ansible-lint diff --git a/scripts/ansible/.ansible-lint b/scripts/ansible/.ansible-lint new file mode 100644 index 0000000..b908f64 --- /dev/null +++ b/scripts/ansible/.ansible-lint @@ -0,0 +1,8 @@ +parsable: true +skip_list: + - '301' # Commands should not change things if nothing needs doing + - '305' # Use shell only when shell functionality is required + - '204' # Lines should be no longer than 160 chars + - '502' # All tasks should be named + +# vim: filetype=yaml From 6cfff89c1e72e9f907a0a84e3c440be63a950843 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:58:25 +0100 Subject: [PATCH 3/7] ansible: Use native ping module --- scripts/ansible/.ansible-lint | 1 - scripts/ansible/ping_playbook.yml | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/ansible/.ansible-lint b/scripts/ansible/.ansible-lint index b908f64..a9514ea 100644 --- a/scripts/ansible/.ansible-lint +++ b/scripts/ansible/.ansible-lint @@ -1,7 +1,6 @@ parsable: true skip_list: - '301' # Commands should not change things if nothing needs doing - - '305' # Use shell only when shell functionality is required - '204' # Lines should be no longer than 160 chars - '502' # All tasks should be named diff --git a/scripts/ansible/ping_playbook.yml b/scripts/ansible/ping_playbook.yml index 0c47625..ffd7697 100755 --- a/scripts/ansible/ping_playbook.yml +++ b/scripts/ansible/ping_playbook.yml @@ -6,6 +6,4 @@ hosts: all tasks: - name: Ping node - shell: "ls" - environment: - PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + ping: From 4b7e0989d18eb7aa65fcb39eec00be44cd85e32c Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:06:19 +0100 Subject: [PATCH 4/7] ansible: Factor out ava-stop role --- scripts/ansible/kill_playbook.yml | 5 ++--- scripts/ansible/restart_playbook.yml | 5 ++--- scripts/ansible/roles/ava-stop/tasks/main.yml | 3 +++ scripts/ansible/update_playbook.yml | 5 ++--- 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 scripts/ansible/roles/ava-stop/tasks/main.yml diff --git a/scripts/ansible/kill_playbook.yml b/scripts/ansible/kill_playbook.yml index 6e91645..03f9231 100755 --- a/scripts/ansible/kill_playbook.yml +++ b/scripts/ansible/kill_playbook.yml @@ -4,6 +4,5 @@ connection: ssh gather_facts: false hosts: all - tasks: - - name: Kill Node - command: killall ava \ No newline at end of file + roles: + - name: ava-stop diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index 93b0bad..0d9a80a 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -9,10 +9,9 @@ repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko-internal repo_branch: platformvm-proposal-accept + roles: + - name: ava-stop tasks: - - name: Kill Node - command: killall ava - ignore_errors: yes - git: repo: ssh://git@github.com/{{ repo_name }}.git dest: "{{ repo_folder }}" diff --git a/scripts/ansible/roles/ava-stop/tasks/main.yml b/scripts/ansible/roles/ava-stop/tasks/main.yml new file mode 100644 index 0000000..1053cf0 --- /dev/null +++ b/scripts/ansible/roles/ava-stop/tasks/main.yml @@ -0,0 +1,3 @@ +- name: Kill Node + command: killall ava + ignore_errors: true diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index c31cf89..e8c5352 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -9,10 +9,9 @@ repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko-internal repo_branch: platformvm-proposal-accept + roles: + - name: ava-stop tasks: - - name: Kill Node - command: killall ava - ignore_errors: yes - git: repo: ssh://git@github.com/{{ repo_name }}.git dest: "{{ repo_folder }}" From 33f0201e2387bdc0b03c7936072f54fd08f4de9c Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:07:43 +0100 Subject: [PATCH 5/7] ansible: Factor out ava-build role --- scripts/ansible/restart_playbook.yml | 12 +----------- scripts/ansible/roles/ava-build/tasks/main.yml | 13 +++++++++++++ scripts/ansible/update_playbook.yml | 12 +----------- 3 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 scripts/ansible/roles/ava-build/tasks/main.yml diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index 0d9a80a..8e6e3b7 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -11,18 +11,8 @@ repo_branch: platformvm-proposal-accept roles: - name: ava-stop + - name: ava-build tasks: - - git: - repo: ssh://git@github.com/{{ repo_name }}.git - dest: "{{ repo_folder }}" - version: "{{ repo_branch }}" - update: yes - - name: Build project - command: ./scripts/build.sh - args: - chdir: "{{ repo_folder }}" - environment: - PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin - name: Remove previous database file: path: "{{ db_dir }}" diff --git a/scripts/ansible/roles/ava-build/tasks/main.yml b/scripts/ansible/roles/ava-build/tasks/main.yml new file mode 100644 index 0000000..d059cda --- /dev/null +++ b/scripts/ansible/roles/ava-build/tasks/main.yml @@ -0,0 +1,13 @@ +- name: Update git clone + git: + repo: ssh://git@github.com/{{ repo_name }}.git + dest: "{{ repo_folder }}" + version: "{{ repo_branch }}" + update: yes + +- name: Build project + command: ./scripts/build.sh + args: + chdir: "{{ repo_folder }}" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index e8c5352..bb32961 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -11,18 +11,8 @@ repo_branch: platformvm-proposal-accept roles: - name: ava-stop + - name: ava-build tasks: - - git: - repo: ssh://git@github.com/{{ repo_name }}.git - dest: "{{ repo_folder }}" - version: "{{ repo_branch }}" - update: yes - - name: Build project - command: ./scripts/build.sh - args: - chdir: "{{ repo_folder }}" - environment: - PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin - name: Start node shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" environment: From 595fada412d550084b00154e59b536dd37214048 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:09:01 +0100 Subject: [PATCH 6/7] ansible: Factor out ava-reset role --- scripts/ansible/restart_playbook.yml | 9 +-------- scripts/ansible/roles/ava-reset/tasks/main.yml | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 scripts/ansible/roles/ava-reset/tasks/main.yml diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index 8e6e3b7..b87f610 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -12,15 +12,8 @@ roles: - name: ava-stop - name: ava-build + - name: ava-reset tasks: - - name: Remove previous database - file: - path: "{{ db_dir }}" - state: absent - - name: Remove previous logs - file: - path: "{{ log_dir }}" - state: absent - name: Start node shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" environment: diff --git a/scripts/ansible/roles/ava-reset/tasks/main.yml b/scripts/ansible/roles/ava-reset/tasks/main.yml new file mode 100644 index 0000000..e2e9bda --- /dev/null +++ b/scripts/ansible/roles/ava-reset/tasks/main.yml @@ -0,0 +1,9 @@ +- name: Remove previous database + file: + path: "{{ db_dir }}" + state: absent + +- name: Remove previous logs + file: + path: "{{ log_dir }}" + state: absent From 383b363540184bd40457e2995aeb63bb6d6dff81 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 30 Apr 2020 21:14:28 +0100 Subject: [PATCH 7/7] ansible: Factor out ava-start role Also took the opportunity to - break the ava command over multiple lines, for cleaner diffs - quote the command line parameters, to handle potential whitespace Due to how YAML collapses whitespace, the rendered command will not contain any newline characters. --- scripts/ansible/restart_playbook.yml | 6 +-- .../ansible/roles/ava-start/tasks/main.yml | 38 +++++++++++++++++++ scripts/ansible/update_playbook.yml | 6 +-- 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 scripts/ansible/roles/ava-start/tasks/main.yml diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index b87f610..ee43d0e 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -13,8 +13,4 @@ - name: ava-stop - name: ava-build - name: ava-reset - tasks: - - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" - environment: - PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + - name: ava-start diff --git a/scripts/ansible/roles/ava-start/tasks/main.yml b/scripts/ansible/roles/ava-start/tasks/main.yml new file mode 100644 index 0000000..fc7f277 --- /dev/null +++ b/scripts/ansible/roles/ava-start/tasks/main.yml @@ -0,0 +1,38 @@ +- name: Start node + shell: + nohup {{ ava_binary }} + --network-id="{{ network_id }}" + --api-admin-enabled="{{ api_admin_enabled }}" + --api-keystore-enabled="{{ api_keystore_enabled }}" + --api-metrics-enabled="{{ api_metrics_enabled }}" + --ava-tx-fee="{{ ava_tx_fee }}" + --assertions-enabled="{{ assertions_enabled }}" + --signature-verification-enabled="{{ signature_verification_enabled }}" + --db-enabled="{{ db_enabled }}" + --db-dir="{{ db_dir }}" + --http-port="{{ http_port }}" + --http-tls-enabled="{{ http_tls_enabled }}" + --http-tls-key-file="{{ http_tls_key_file }}" + --http-tls-cert-file="{{ http_tls_cert_file }}" + --bootstrap-ips="{{ bootstrap_ips }}" + --bootstrap-ids="{{ bootstrap_ids }}" + --public-ip="{{ ansible_host }}" + --staking-port="{{ staking_port }}" + --staking-tls-enabled="{{ staking_tls_enabled }}" + --staking-tls-key-file="{{ staking_tls_key_file }}" + --staking-tls-cert-file="{{ staking_tls_cert_file }}" + --plugin-dir="{{ plugin_dir }}" + --log-dir="{{ log_dir }}" + --log-level="{{ log_level }}" + --snow-sample-size="{{ snow_sample_size }}" + --snow-quorum-size="{{ snow_quorum_size }}" + --snow-virtuous-commit-threshold="{{ snow_virtuous_commit_threshold }}" + --snow-rogue-commit-threshold="{{ snow_rogue_commit_threshold }}" + --snow-avalanche-num-parents="{{ snow_avalanche_num_parents }}" + --snow-avalanche-batch-size="{{ snow_avalanche_batch_size }}" + --api-ipcs-enabled="{{ api_ipcs_enabled }}" + --xput-server-enabled="{{ xput_server_enabled }}" + --xput-server-port="{{ xput_server_port }}" + >/dev/null 2>&1 & + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index bb32961..b704eee 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -12,8 +12,4 @@ roles: - name: ava-stop - name: ava-build - tasks: - - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" - environment: - PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + - name: ava-start