Here is my Ansible Task -
That mount a directory with an external ebs volume in EC2 instance to make an Amazon EBS volume available.
- name: Create Data directory #1
file:
path: "{{ data_directory }}/"
state: directory
- name: Get the EBS volume/block #2
shell: lsblk -x SIZE | grep disk | tail -1 | awk '{print $1}'
register: ebs_nvme_block
check_mode: false
- name: Printout the block #3
debug:
var: ebs_nvme_block.stdout_lines[0]
- name: Create a xfs filesystem on EBS volume #4
filesystem:
fstype: xfs
dev: "/dev/{{ ebs_nvme_block.stdout_lines[0] }}"
ignore_errors: "{{ ansible_check_mode }}"
- name: Get UUID of ebs volume #5
shell: lsblk -o +UUID | grep "{{ ebs_nvme_block.stdout_lines[0] }}" | awk '{print $NF}'
register: uuid
check_mode: false
- name: Print UUID #6
debug:
var: uuid.stdout
- name: Mount the ebs volume with /data directory #6
mount:
backup: yes
path: "{{ data_directory }}"
src: "/dev/{{ ebs_nvme_block.stdout_lines[0] }}" # or use UUID={{ uuid.stdout }}
state: mounted
opts: defaults,nofail
dump: 0
passno: 2
fstype: xfs
ignore_errors: "{{ ansible_check_mode }}"
Now this #6 code block mounts and creates a backup of /etc/fstab
and updates as follows
LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0
/dev/nvme1n1 /data xfs defaults,nofail 0 2
If I use UUID
to mount then the /etc/fstab
is modified as
LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0
UUID=XXXXXXXXXXXXXXXX /data xfs defaults,nofail 0 0
#7 block code update the /etc/fstab
as
LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0
UUID={{ uuid.stdout }} {{ data_directory }} xfs defaults,nofail 0 2
Everything works fine. I don't receive any error while mounting but whatever the reason the EC2 instance is getting Status check error [1/2 checks passed
].
- 1st question is - is there any format of
/etc/fstab
file. is there single space or double space in between values? - From here How fstab works and Make an Amazon EBS volume available for use on Linux, what I got is
- there are 2 spaces in between fields. When Ansible modifies the
fstab
file, it doesn't create any extra space.
UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2
UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2
[Ansible modifies]
- Does it have any effect in status check?
- Ansible creates the backfile as
fstab.DATETIME~
. Same question, does this backup file has any effect of status check error.