0

I want to:

  1. mount /dev/xvdb1 to /mnt/newvar
  2. copy files from /var/ to /mnt/newvar
  3. mount /dev/xvdb1 to /var

But when i do this with ansible i got double entries in fstab and it should replace the previous one, any solution for this issue?:

UUID=7698aac5-0a24-333f-a8c3-b76349gec0e2 /mnt/newvar ext4 defaults,noauto 0 0

UUID=7698aac5-0a24-333f-a8c3-b76349gec0e2 /var ext4 defaults 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 }}"
Dejan Bodiroga
  • 143
  • 2
  • 12

1 Answers1

0

As you're mounting the same UUID twice is being added to /etc/fstab twice as the mount ansible module works like this:
enter image description here

So it'll always modify /etc/fstab unless you use absent but it's not your case

This is still under discussion here:
https://github.com/ansible/ansible/issues/48134

I think you can use shell module if you want to mount only

Example:

- shell: |
    mount /dev/xvdb1 /var
Hernan Garcia
  • 1,416
  • 1
  • 13
  • 24