使用 Ansible 创建并挂载 GlusterFS 卷

使用 Ansible 创建并挂载 GlusterFS 卷

我使用 GlusterFS 在 4 台机器上创建和安装卷。例如,这些机器分别称为machine1machine2和。machine3machine4

我的同行已经被成功探查。

我使用以下命令来创建我的卷:

sudo gluster volume create ssl replica 2 transport tcp machine1:/srv/gluster/ssl machine2:/srv/gluster/ssl machine3:/srv/gluster/ssl machine4:/srv/gluster/ssl force

然后我使用以下命令启动该卷:

sudo gluster volume start ssl

我已经/myproject/ssl使用以下命令挂载了该目录:

sudo mount -t glusterfs machine1:/ssl /myproject/ssl

当安装在每台机器上时,一切都按预期工作,并且/myproject/ssl目录具有在所有机器之间共享的数据。

问题是,我究竟该如何通过 Ansible 方式做到这一点?

以下是我以 Ansible 方式执行这两个命令的尝试:

- name: Configure Gluster volume.
  gluster_volume:
    state: present
    name: "{{ gluster.brick_name }}"
    brick: "{{ gluster.brick_dir }}"
    replicas: 2
    cluster: "{{ groups.glusterssl | join(',') }}"
    host: "{{ inventory_hostname }}"
    force: yes
  become: true
  become_user: root
  become_method: sudo
  run_once: true
  ignore_errors: true

- name: Ensure Gluster volume is mounted.
  mount:
    name: "{{ gluster.brick_name }}"
    src: "{{ inventory_hostname }}:/{{ gluster.brick_name }}"
    fstype: glusterfs
    opts: "defaults,_netdev"
    state: mounted
  become: true
  become_user: root
  become_method: sudo

尽管对等探测已在前一个任务中成功返回,但该Configure Gluster volume任务仍失败并显示:

fatal: [machine3]: FAILED! => 
  {"changed": false, 
   "failed": true, 
   "invocation": {
     "module_args": {
       "brick": "/srv/gluster/ssl",
       "bricks": "/srv/gluster/ssl", 
       "cluster": ["machine1", "machine2", "machine3", "machine4"],
       "directory": null, 
       "force": true, 
       "host": "machine3", 
       "name": "ssl", 
       "options": {}, 
       "quota": null, 
       "rebalance": false, 
       "replicas": 2, 
       "start_on_create": true, 
       "state": "present", 
       "stripes": null, 
       "transport": "tcp"}, 
     "module_name": "gluster_volume"}, 
   "msg": "failed to probe peer machine1 on machine3"}

如果我用我建议的第一个 shell 命令替换这个 Ansible 任务,一切都会正常工作,但随后会Ensure Gluster volume is mounted失败:

fatal: [machine3]: FAILED! => 
  {"changed": false, 
   "failed": true, 
   "invocation": {
     "module_args": {
       "dump": null, 
       "fstab": "/etc/fstab", 
       "fstype": "glusterfs", 
       "name": "ssl", "opts": 
       "defaults,_netdev", 
       "passno": null, "src": 
       "machine3:/ssl", 
       "state": "mounted"}, 
     "module_name": "mount"}, 
   "msg": "Error mounting ssl: Mount failed. Please check the log file for more details.\n"}

相关日志输出为:

[2016-10-17 09:10:25.602431] E [MSGID: 114058] [client-handshake.c:1524:client_query_portmap
_cbk] 2-ssl-client-3: failed to get the port number for remote subvolume. Please run 'gluster volume status' on server to see if brick process is running.
[2016-10-17 09:10:25.602480] I [MSGID: 114018] [client.c:2042:client_rpc_notify] 2-ssl-client-3: disconnected from ssl-client-3. Client process will keep trying to connect to glusterd until brick's port is available
[2016-10-17 09:10:25.602500] E [MSGID: 108006] [afr-common.c:3880:afr_notify] 2-ssl-replicate-1: All subvolumes are down. Going offline until atleast one of them comes back up.
[2016-10-17 09:10:25.616402] I [fuse-bridge.c:5137:fuse_graph_setup] 0-fuse: switched to graph 2

因此,该卷不会由 Ansible 任务启动。

我的问题本质上是,如何以与上面提到的 3 个命令相同的方式(即 Ansible 方式)创建、挂载和启动卷?

答案1

您应该使用以下命令启动该卷state: started

- name: Configure Gluster volume.
  gluster_volume:
    state: started
    name: "{{ gluster.brick_name }}"
    brick: "{{ gluster.brick_dir }}"
    replicas: 2
    cluster: "{{ groups.glusterssl | join(',') }}"
    host: "{{ inventory_hostname }}"
    force: yes
  become: true
  become_user: root
  become_method: sudo
  run_once: true
  ignore_errors: true

相关内容