Skip to content

Commit b71459b

Browse files
committed
replace_node: Replace a gluster node with a new one with same name
1 parent 910feaa commit b71459b

File tree

21 files changed

+493
-1
lines changed

21 files changed

+493
-1
lines changed

README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
# gluster-ansible-maintenance
1+
Role Name
2+
=========
3+
4+
A brief description of the role goes here.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
10+
11+
Role Variables
12+
--------------
13+
14+
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
15+
16+
Dependencies
17+
------------
18+
19+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
20+
21+
Example Playbook
22+
----------------
23+
24+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25+
26+
- hosts: servers
27+
roles:
28+
- { role: username.rolename, x: 42 }
29+
30+
License
31+
-------
32+
33+
BSD
34+
35+
Author Information
36+
------------------
37+
38+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

defaults/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# defaults file for gluster-ansible-maintenance

examples/replace_node.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- remote_user: root
3+
gather_facts: no
4+
hosts: server
5+
vars:
6+
- gluster_maintenance_old_node: store
7+
- gluster_maintenance_new_node: store
8+
- gluster_maintenance_cluster_node: data
9+
roles:
10+
- gluster.maintenance
11+

handlers/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for gluster-ansible-maintenance

meta/main.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
galaxy_info:
2+
author: your name
3+
description: your description
4+
company: your company (optional)
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Some suggested licenses:
11+
# - BSD (default)
12+
# - MIT
13+
# - GPLv2
14+
# - GPLv3
15+
# - Apache
16+
# - CC-BY
17+
license: license (GPLv2, CC-BY, etc)
18+
19+
min_ansible_version: 1.2
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
# Optionally specify the branch Galaxy will use when accessing the GitHub
25+
# repo for this role. During role install, if no tags are available,
26+
# Galaxy will use this branch. During import Galaxy will access files on
27+
# this branch. If Travis integration is configured, only notifications for this
28+
# branch will be accepted. Otherwise, in all cases, the repo's default branch
29+
# (usually master) will be used.
30+
#github_branch:
31+
32+
#
33+
# platforms is a list of platforms, and each platform has a name and a list of versions.
34+
#
35+
# platforms:
36+
# - name: Fedora
37+
# versions:
38+
# - all
39+
# - 25
40+
# - name: SomePlatform
41+
# versions:
42+
# - all
43+
# - 1.0
44+
# - 7
45+
# - 99.99
46+
47+
galaxy_tags: []
48+
# List tags for your role here, one per line. A tag is a keyword that describes
49+
# and categorizes the role. Users find roles by searching for tags. Be sure to
50+
# remove the '[]' above, if you add tags to this list.
51+
#
52+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
53+
# Maximum 20 tags per role.
54+
55+
dependencies: []
56+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
57+
# if you add dependencies to this list.

roles/replace_node/#README.md#

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Role Name
2+
=========
3+
4+
replace_node - Replace gluster node with a new node.
5+
6+
Requirements
7+
------------
8+
9+
- Ansible >= 2.6
10+
- lvm2 (Optional)
11+
12+
NOTE: Inventory should contain a single node, which should be part of the cluster. This node should be different than any of the three variables explained below, this requirement is to collect the right peers for the new node.
13+
14+
Role Variables
15+
--------------
16+
17+
| Name |Choices| Default value | Comments |
18+
|--------------------------|-------|-----------------------|-----------------------------------|
19+
| gluster_maintenance_old_node | | UNDEF | The node which has to be replaced with a new node. Just the node name is needed to get the peer id, the node need not be accessible. Provide the name that was used to probe the peers. |
20+
| gluster_maintenance_new_node | | UNDEF | New node which will replace the old node. This name can be same as the old node or different name. |
21+
| gluster_maintenance_cluster_node | | UNDEF | The node on which the peer, volume-id details are collected. This node should be part of the trusted storage pool. And should be different from old_node or new_node. |
22+
23+
24+
25+
Dependencies
26+
------------
27+
28+
Depends on:
29+
30+
- gluster.repositories (Optional: to subscribe to channels)
31+
- gluster.infra (Optional: to setup bricks)
32+
33+
Example Playbook
34+
----------------
35+
36+
Note that `server' in the inventory and the variable gluster_maintenance_cluster_node are unique (if the number of nodes are more than 2).
37+
38+
```
39+
---
40+
- remote_user: root
41+
gather_facts: no
42+
hosts: server
43+
vars:
44+
- gluster_maintenance_old_node: store
45+
- gluster_maintenance_new_node: store
46+
- gluster_maintenance_cluster_node: data
47+
roles:
48+
- gluster.maintenance
49+
```
50+
51+
In the above example, a new host named store will replace the old host (the replaced node has the same hostname as the old node, however ensure that old node is not accessible with the hostname, else
52+
53+
54+
License
55+
-------
56+
57+
GPLv3

roles/replace_node/.#README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[email protected].17865:1533605177

roles/replace_node/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Role Name
2+
=========
3+
4+
replace_node - Replace gluster node with a new node.
5+
6+
Requirements
7+
------------
8+
9+
- Ansible >= 2.6
10+
- lvm2 (Optional)
11+
12+
NOTE: Inventory should contain a single node, which should be part of the cluster. This node should be different than any of the three variables explained below, this requirement is to collect the right peers for the new node.
13+
14+
Role Variables
15+
--------------
16+
17+
| Name |Choices| Default value | Comments |
18+
|--------------------------|-------|-----------------------|-----------------------------------|
19+
| gluster_maintenance_old_node | | UNDEF | The node which has to be replaced with a new node. Just the node name is needed to get the peer id, the node need not be accessible. Provide the name that was used to probe the peers. |
20+
| gluster_maintenance_new_node | | UNDEF | New node which will replace the old node. This name can be same as the old node or different name. |
21+
| gluster_maintenance_cluster_node | | UNDEF | The node on which the peer, volume-id details are collected. This node should be part of the trusted storage pool. And should be different from old_node or new_node. |
22+
23+
24+
25+
Dependencies
26+
------------
27+
28+
Depends on:
29+
30+
- gluster.repositories (Optional: to subscribe to channels)
31+
- gluster.infra (Optional: to setup bricks)
32+
33+
Example Playbook
34+
----------------
35+
36+
Note that `server' in the inventory and the variable gluster_maintenance_cluster_node are unique (if the number of nodes are more than 2).
37+
38+
```
39+
---
40+
- remote_user: root
41+
gather_facts: no
42+
hosts: server
43+
vars:
44+
- gluster_maintenance_old_node: store
45+
- gluster_maintenance_new_node: store
46+
- gluster_maintenance_cluster_node: data
47+
roles:
48+
- gluster.maintenance
49+
```
50+
51+
52+
License
53+
-------
54+
55+
GPLv3

roles/replace_node/defaults/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# defaults file for replace_node

roles/replace_node/handlers/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for replace_node

roles/replace_node/meta/main.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
galaxy_info:
2+
author: your name
3+
description: your description
4+
company: your company (optional)
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Some suggested licenses:
11+
# - BSD (default)
12+
# - MIT
13+
# - GPLv2
14+
# - GPLv3
15+
# - Apache
16+
# - CC-BY
17+
license: license (GPLv2, CC-BY, etc)
18+
19+
min_ansible_version: 1.2
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
# Optionally specify the branch Galaxy will use when accessing the GitHub
25+
# repo for this role. During role install, if no tags are available,
26+
# Galaxy will use this branch. During import Galaxy will access files on
27+
# this branch. If Travis integration is configured, only notifications for this
28+
# branch will be accepted. Otherwise, in all cases, the repo's default branch
29+
# (usually master) will be used.
30+
#github_branch:
31+
32+
#
33+
# platforms is a list of platforms, and each platform has a name and a list of versions.
34+
#
35+
# platforms:
36+
# - name: Fedora
37+
# versions:
38+
# - all
39+
# - 25
40+
# - name: SomePlatform
41+
# versions:
42+
# - all
43+
# - 1.0
44+
# - 7
45+
# - 99.99
46+
47+
galaxy_tags: []
48+
# List tags for your role here, one per line. A tag is a keyword that describes
49+
# and categorizes the role. Users find roles by searching for tags. Be sure to
50+
# remove the '[]' above, if you add tags to this list.
51+
#
52+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
53+
# Maximum 20 tags per role.
54+
55+
dependencies: []
56+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
57+
# if you add dependencies to this list.

roles/replace_node/tasks/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# Create tmp dir for storing peer data
3+
- name: Create temporary storage directory
4+
tempfile:
5+
state: directory
6+
suffix: _peer
7+
register: tmpdir
8+
delegate_to: 127.0.0.1
9+
run_once: True
10+
11+
# Set the glusterd location
12+
- name: Set the path of glusterd.info file
13+
set_fact:
14+
glusterd_libdir: "/var/lib/glusterd"
15+
peer_tmp_dir: "{{ tmpdir['path'] }}"
16+
17+
- import_tasks: peers.yml
18+
19+
- import_tasks: volume.yml
20+
21+
# Ensure to delete the temporary directory
22+
- name: Delete the temporary directory
23+
file:
24+
state: absent
25+
path: "{{ peer_tmp_dir }}"
26+
delegate_to: 127.0.0.1
27+
run_once: True

roles/replace_node/tasks/peers.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Fetch the UUID of the old node
3+
shell: >
4+
gluster peer status |
5+
grep -A1 {{ gluster_maintenance_old_node | mandatory }} |
6+
awk -F: '/uid/ { print $2}'
7+
register: old_node_uuid
8+
run_once: true
9+
10+
- name: Get the UUID of master
11+
shell: awk -F= '/UUID/{print $2}' "{{ glusterd_libdir }}/glusterd.info"
12+
register: master_uuid
13+
run_once: true
14+
15+
- name: Store the UUID
16+
set_fact:
17+
old_uuid: "{{ old_node_uuid.stdout | trim }}"
18+
master_uuid: "{{ master_uuid.stdout }}"
19+
20+
- name: Edit the new node's gluster.info
21+
lineinfile:
22+
path: "{{ glusterd_libdir }}/glusterd.info"
23+
regexp: '^UUID='
24+
line: "UUID={{ old_uuid }}"
25+
delegate_to: "{{ gluster_maintenance_new_node | mandatory }}"
26+
27+
- name: Copy the peer data into local
28+
synchronize:
29+
mode: pull
30+
src: "{{ glusterd_libdir }}/peers"
31+
dest: "{{ peer_tmp_dir }}"
32+
run_once: true
33+
34+
- name: Copy the peer data of master node
35+
fetch:
36+
flat: yes
37+
src: "{{ glusterd_libdir }}/peers/{{ master_uuid }}"
38+
dest: "{{ peer_tmp_dir }}/peers/{{ master_uuid }}"
39+
delegate_to: "{{ gluster_maintenance_cluster_node | mandatory }}"
40+
41+
- name: Delete the peer of the old node
42+
file:
43+
state: absent
44+
path: "{{ peer_tmp_dir }}/peers/{{ old_uuid }}"
45+
delegate_to: 127.0.0.1
46+
47+
- name: Copy the peer data to remote node
48+
copy:
49+
src: "{{ peer_tmp_dir }}/peers/"
50+
dest: "{{ glusterd_libdir }}/peers"
51+
delegate_to: "{{ gluster_maintenance_new_node }}"

0 commit comments

Comments
 (0)