Skip to content

Commit

Permalink
reduce regex complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
voidquark committed Oct 18, 2024
1 parent ff2f191 commit 5324afb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions roles/alloy/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
block:
- name: Search for server.http.listen-addr string
ansible.builtin.set_fact:
__alloy_server_http_listen_addr_regex: "{{ alloy_env_file_vars.CUSTOM_ARGS | regex_search('--server.http.listen-addr=([\\d\\.]+):(\\d+)') }}"
__alloy_server_http_listen_addr_regex: "{{ alloy_env_file_vars.CUSTOM_ARGS | regex_search('--server.http.listen-addr=([\\d\\.]+):(\\d+)', '\\1', '\\2') }}"

- name: Extract IP address and port
ansible.builtin.set_fact:
__alloy_server_http_listen_address: "{{ __alloy_server_http_listen_addr_regex | regex_search('(?<!:)(\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b)(?=:)') }}"
__alloy_server_http_listen_port: "{{ __alloy_server_http_listen_addr_regex | regex_search('(?<=:)(\\d+)$') }}"
__alloy_server_http_listen_address: "{{ __alloy_server_http_listen_addr_regex[0] }}"
__alloy_server_http_listen_port: "{{ __alloy_server_http_listen_addr_regex[1] }}"
when: __alloy_server_http_listen_addr_regex | length > 0

- name: Assert that extracted IP address is valid
Expand Down

0 comments on commit 5324afb

Please sign in to comment.