使用Ansible在fstab中两次输入

时间:2019-03-07 17:28:34

标签: ansible ansible-2.x

我要:

  1. 将/ dev / xvdb1挂载到/ mnt / newvar
  2. 将文件从/ var /复制到/ mnt / newvar
  3. 将/ dev / xvdb1挂载到/ var

但是当我用ansible执行此操作时,我在fstab中得到了两次输入,并且它应该替换前一个,对此问题有解决方案吗?:

UUID = 7698aac5-0a24-333f-a8c3-b76349gec0e2 / mnt / newvar ext4默认值为noauto 0 0

UUID = 7698aac5-0a24-333f-a8c3-b76349gec0e2 / var ext4默认值为0 2

- name: "Get UUID for partition"
  command: "lsblk -no UUID /dev/xvdb1"
  register: with_output

- name: Mount /mnt/newvar to /dev/xvdb1
  mount:
    path: "{{ newvar_dir }}"
    src: "UUID={{ item }}"
    fstype: "{{ volume_filesystem_type }}"
    opts: "defaults,noauto"
    state: mounted
  with_items: 
    - "{{ with_output.stdout_lines }}"

- name: copy files from /var/* to /mnt/newvar 
  synchronize:
    src: /var/
    dest: "{{ newvar_dir }}"
    recursive: yes
    archive: yes
    delete: False
  delegate_to: "{{ vault_ip }}"

- name: Mount /dev/xvdb1 to /var
  mount:
    path: /var
    src: "UUID={{ item }}"
    fstype: "{{ volume_filesystem_type }}"
    opts: defaults
    state: mounted
    passno: 2
  with_items: 
    - "{{ with_output.stdout_lines }}"

1 个答案:

答案 0 :(得分:0)

由于UUID ansible模块的工作原理如下,在两次安装相同的/etc/fstab时,两次被添加到mount中:
enter image description here

因此,除非您使用/etc/fstab,否则它将始终修改absent,但这不是您的情况

此处仍在讨论中:
https://github.com/ansible/ansible/issues/48134

如果您只想挂载

,我认为您可以使用shell模块

示例:

- shell: |
    mount /dev/xvdb1 /var