【问题标题】:Double entry in fstab using Ansible使用 Ansible 在 fstab 中进行双重输入
【发布时间】:2019-03-07 17:28:33
【问题描述】:

我想:

  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 }}"

【问题讨论】:

    标签: ansible ansible-2.x


    【解决方案1】:

    当您安装相同的 UUID 两次时,/etc/fstab 会被添加两次,因为 mount ansible 模块的工作方式如下:

    所以它总是会修改/etc/fstab,除非你使用absent,但这不是你的情况

    这里仍在讨论中:
    https://github.com/ansible/ansible/issues/48134

    如果你只想挂载,我认为你可以使用shell 模块

    例子:

    - shell: |
        mount /dev/xvdb1 /var
    

    【讨论】:

    • 谢谢,是的,我可以使用 shell 或: - 名称:卸载 /mnt/newvar 安装:路径:“{{ newvar_dir }}”状态:缺席
    猜你喜欢
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多