Skip to content

Instantly share code, notes, and snippets.

@ggnanasekaran77
Last active October 31, 2021 01:25
Show Gist options
  • Save ggnanasekaran77/a38672fba3b122e97e8761d18b03a8db to your computer and use it in GitHub Desktop.
Save ggnanasekaran77/a38672fba3b122e97e8761d18b03a8db to your computer and use it in GitHub Desktop.
--- # apache_balancer_manager_role do.yml
- name: member_host
debug:
msg: "member_host {{ member_host }}"
- name: "Get the balancer_manager content"
uri:
url: "{{ apache.balancer.url }}"
follow_redirects: yes
return_content: yes
force: yes
validate_certs: False
url_username: "{{ apache.balancer.username }}"
url_password: "{{ apache.balancer.password }}"
headers:
Host: "{{ apache.domain.name }}"
register: balancer_manager
- name: set_fact for balancer_name and worker_list
set_fact:
balancer_name: "{{ balancer_manager.content | regex_search ('b=.*' + member_host) | regex_replace ('.*b=(.*)&w.*', '\\1') }}"
worker_list: "{{ balancer_manager.content | regex_findall ('w=.*' + member_host + '.*nonce') }}"
worker_count: "{{ balancer_manager.content | regex_findall ('w=.*' + member_host + '.*nonce') | length }}"
nonce_id: "{{ balancer_manager.content | regex_search ('nonce=.*' + member_host) | regex_replace ('.*nonce=(.*)\".*', '\\1') }}"
- name: Balancer name
debug:
msg: "[DEVOPS-INFO] balancer_name {{ balancer_name }}"
- name: Nonce ID
debug:
msg: "[DEVOPS-INFO] nonce_id {{ nonce_id }}"
- name: worker_count
debug:
msg: "worker_count {{ worker_count }}"
- name: set_fact for worker_name_list
set_fact:
worker_name: "{{ item | regex_replace ('.*w=(.*)&nonce', '\\1') }}"
with_items: "{{ worker_list }}"
register: worker_name_list
- name: Worker names
debug:
msg: "[DEVOPS-INFO] {{ item.ansible_facts.worker_name }}"
with_items: "{{ worker_name_list.results }}"
- name: "Worker action {{ w_status_D }}"
uri:
url: "{{ apache.balancer.url }}"
method: POST
body_format: form-urlencoded
follow_redirects: yes
force: yes
validate_certs: False
url_username: "{{ apache.balancer.username }}"
url_password: "{{ apache.balancer.password }}"
headers:
Host: "{{ apache.domain.name }}"
body:
- [b, "{{ balancer_name }}"]
- [w, "{{ item.ansible_facts.worker_name }}"]
- [nonce, "{{ nonce_id }}"]
- [w_status_D, "{{ w_status_D }}"]
with_items: "{{ worker_name_list.results }}"
--- #apache_balancer_manager_role test.yml
- name: "Get the balancer_manager content for test"
uri:
url: "{{ apache.balancer.url }}"
follow_redirects: yes
return_content: yes
validate_certs: False
force: yes
url_username: "{{ apache.balancer.username }}"
url_password: "{{ apache.balancer.password }}"
headers:
Host: "{{ apache.domain.name }}"
register: balancer_manager_test
- name: "Get the worker_count_test for Init Ok"
set_fact:
worker_count_test: "{{ balancer_manager_test.content | regex_findall (member_host + '.*Init Ok') | length }}"
when: "w_status_D == 0"
- name: "Get the worker_count_testi for Init Dis"
set_fact:
worker_count_test: "{{ balancer_manager_test.content | regex_findall (member_host + '.*Init Dis') | length }}"
when: "w_status_D == 1"
- name: assert worker action
assert:
that:
- worker_count_test == worker_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment