From 16fbd02a499c70bcb154c75f8af7b9cf62d37dae Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Wed, 6 Dec 2023 14:40:26 +1000 Subject: [PATCH] adding in fleet mode --- defaults/main.yml | 8 +++++ tasks/fleet.yml | 75 ++++++++++++++++++++++++++++++++++++++++ tasks/install.yml | 2 +- tasks/main.yml | 4 +++ templates/config.toml.j2 | 14 +++++++- 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tasks/fleet.yml diff --git a/defaults/main.yml b/defaults/main.yml index a173913..69fc147 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -84,6 +84,14 @@ besu_tx_pool_max_size: 4096 besu_tx_pool_price_bump: 10 besu_tx_pool_retention_hours: 13 +# fleet mode plugin +#LEADER/FOLLOWER +besu_plugin_fleet_node_role: "" +besu_plugin_fleet_leader_http_host: "" +beus_plugin_fleet_leader_http_port: 8545 +besu_plugin_fleet_follower_http_host: 0.0.0.0 +besu_plugin_fleet_follower_http_port: 8545 + # privacy besu_privacy_enabled: "false" besu_privacy_url: "http://127.0.0.1:8888" diff --git a/tasks/fleet.yml b/tasks/fleet.yml new file mode 100644 index 0000000..a2de3c5 --- /dev/null +++ b/tasks/fleet.yml @@ -0,0 +1,75 @@ + +--- +- name: Get the default ipv4 address + set_fact: + besu_default_ip: >- + {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] if + hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is + defined else '127.0.0.1' }} + besu_aws_private_ip: "" + besu_gcp_private_ip: "" + besu_azure_private_ip: "" + +- name: Check if running on AWS + uri: + url: http://169.254.169.254/latest/meta-data/local-ipv4 + method: GET + return_content: yes + status_code: 200 + register: aws_private_ip_output + ignore_errors: True + when: (besu_plugin_fleet_node_role=="FOLLOWER") + +- name: Set the host ip if we are in AWS + set_fact: + besu_plugin_fleet_follower_http_host: "{{ aws_private_ip_output.content }}" + when: (besu_plugin_fleet_node_role=="FOLLOWER") and + (aws_private_ip_output.status == 200) + +- name: Check if running on Azure + uri: + url: http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/privateIpAddress?api-version=2017-08-01&format=text + method: GET + headers: + Metadata: true + return_content: yes + status_code: 200 + register: azure_private_ip_output + ignore_errors: True + when: (besu_plugin_fleet_node_role=="FOLLOWER") and + ( aws_private_ip_output.status != 200 ) + +- name: Set the host ip if we are in Azure + set_fact: + besu_host_ip: "{{ azure_private_ip_output.content }}" + when: (besu_plugin_fleet_node_role=="FOLLOWER") and + ( aws_private_ip_output.status != 200 ) and + ( azure_private_ip_output.status == 200 ) + +- name: Check if running on GCP + uri: + url: http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/ip + method: GET + headers: + Metadata-Flavor: Google + return_content: yes + status_code: 200 + register: gcp_private_ip_output + ignore_errors: True + when: (besu_plugin_fleet_node_role=="FOLLOWER") and + ( aws_private_ip_output.status != 200 ) and + ( azure_private_ip_output.status != 200 ) + +- name: Set the host ip if we are in GCP + set_fact: + besu_host_ip: "{{ gcp_private_ip_output.content }}" + when: ( aws_private_ip_output.status != 200 ) and + ( azure_private_ip_output.status != 200 ) and + ( gcp_private_ip_output == 200 ) + +- name: Fallback to the ansible default ip + set_fact: + besu_host_ip: "{{ besu_default_ip }}" + when: ( aws_private_ip_output.status != 200 ) and + ( azure_private_ip_output.status != 200 ) and + ( gcp_private_ip_output != 200 ) diff --git a/tasks/install.yml b/tasks/install.yml index 64fe7a9..1390c1c 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -57,7 +57,7 @@ - name: Create a symlink to current file: - src: "{{ besu_install_dir }}/" + src: "{{ besu_install_dir }}/"v dest: "{{ besu_current_dir }}" state: link become: true diff --git a/tasks/main.yml b/tasks/main.yml index f426897..3af0b20 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -46,6 +46,10 @@ include_tasks: "network.yml" when: not besu_host_ip +- name: Get private IP address to bind to if not provided for fleet mode + include_tasks: "fleet.yml" + when: not besu_plugin_fleet_node_role + - name: Create config include_tasks: "config.yml" diff --git a/templates/config.toml.j2 b/templates/config.toml.j2 index 188e650..7cb8683 100644 --- a/templates/config.toml.j2 +++ b/templates/config.toml.j2 @@ -181,7 +181,19 @@ privacy-marker-transaction-signing-key-file="{{besu_privacy_marker_tx_signing_ke {% endif %} {% endif %} +{% if besu_plugin_fleet_node_role != "" %} +{% if besu_plugin_fleet_node_role == "LEADER" %} +plugin-fleet-node-role="LEADER" +{% else %} +plugin-fleet-node-role="FOLLOWER" +plugin-fleet-leader-http-host="{{besu_plugin_fleet_leader_http_host}}" +plugin-fleet-leader-http-port={{beus_plugin_fleet_leader_http_port}} +plugin-fleet-follower-http-host="{{besu_plugin_fleet_follower_http_host}}" +plugin-fleet-leader-http-port={{besu_plugin_fleet_follower_http_port}} +{% endif %} +{% endif %} + {% if besu_xdns_enabled|bool == True %} Xdns-enabled=true Xdns-update-enabled=true -{% endif %} \ No newline at end of file +{% endif %}