forked from ansible/workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable-pool-member.yml
67 lines (59 loc) · 2.16 KB
/
disable-pool-member.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
- name: "Disabling a pool member"
hosts: lb
gather_facts: false
connection: local
tasks:
- name: Setup provider
set_fact:
provider:
server: "{{private_ip}}"
user: "{{ansible_user}}"
password: "{{ansible_ssh_pass}}"
server_port: 8443
validate_certs: false
- name: Query BIG-IP facts
f5networks.f5_modules.bigip_device_info:
provider: "{{provider}}"
gather_subset:
- ltm-pools
register: bigip_facts
- name: Display Pools available
debug: "msg={{item.name}}"
loop: "{{bigip_facts.ltm_pools}}"
loop_control:
label: "{{item.name}}"
- name: Store pool name in a variable
set_fact:
pool_name: "{{item.name}}"
loop: "{{bigip_facts.ltm_pools}}"
no_log: true
- name: "Show members belonging to pool {{pool_name}}"
debug: "msg={{item}}"
loop: "{{bigip_facts.ltm_pools | json_query(query_string)}}"
vars:
query_string: "[?name=='{{pool_name}}'].members[*].name[]"
- pause:
prompt: "To disable a particular member enter member with format member_name:port \nTo disable all members of the pool enter 'all'"
register: member_name
- name: Disable ALL pool members
f5networks.f5_modules.bigip_pool_member:
provider: "{{provider}}"
state: "forced_offline"
name: "{{item.split(':')[0]}}"
pool: "{{pool_name}}"
port: "{{item.split(':')[1]}}"
host: "{{hostvars[item.split(':')[0]].ansible_host}}"
loop: "{{bigip_facts.ltm_pools | json_query(query_string)}}"
vars:
query_string: "[?name=='{{pool_name}}'].members[*].name[]"
when: '"all" in member_name.user_input'
- name: Disable pool member {{member_name.user_input}}
f5networks.f5_modules.bigip_pool_member:
provider: "{{provider}}"
state: "forced_offline"
name: "{{member_name.user_input.split(':')[0]}}"
pool: "{{pool_name}}"
port: "{{member_name.user_input.split(':')[1]}}"
host: "{{hostvars[member_name.user_input.split(':')[0]].ansible_host}}"
when: '"all" not in member_name.user_input'