I'm trying to create an EBS role for my Ansible scripts. I'm going to be creating the EBS volume and attaching it myself for now through the console. I want this role to run commands and mount the drive if the drive isn't already mounted, but skip this if it's already mounted.
I have host specific vars that give a list of disks and mount points:
ebs_vols:
- drive: /dev/sdb
mount_point: /mnt/ebs1
directory: /var/lib/mysql
- drive: /dev/sdc
mount_point: /mnt/ebs2
directory: /var/backups
I want to have my task check each drive with a df
command and see if it's mounted. Then skip commands if the drive is mounted:
- name: Check if drives are already mounted
shell: df | grep "{{item.drive}}" | wc -l
with_items: "{{ebs_vols}}"
register: ebs_checked
- name: output debug
debug: var=ebs_checked
- name: Make filesystem
filesystem:
fstype: xfs
dev: "{{item.item.drive}}"
when: "{{item.stdout}} == 0"
with_items: ebs_checked.results
When I run it, it seems to check each disk just fine because the output of the debug
is an object with the correct drives and stdout. The problem is with the Make filesystem
task. The errors out with the following error:
The conditional check '{{item.stdout}} == 0' failed. The error was: error while evaluating conditional ({{item.stdout}} == 0): 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'stdout'\n\n
What am I missing here and what is the best way to skip commands if the drive is already mounted?