I have a playbook that requires to run disk format on 3 servers. The servers are under a worker group
In my main playbook, I’m calling to “disk_managment” playbook and I’m reading variables from an external file
Main Playbook:
### Format worker disks ##
- hosts: worker
become: true
vars_files:
- ./cloudera_environment.yml
tasks:
- name: Worker server disk format
include: disk_management.yml
with_items: "{{ worker_disks }}"
Variable file - Disk information
worker_disks:
- {drive: /dev/sdb ,mount_path: /data1, partition_id: 1}
- {drive: /dev/sdc ,mount_path: /data2, partition_id: 1}
- {drive: /dev/sdd ,mount_path: /data3, partition_id: 1}
Disk management playbook - I have 4 tasks
- name: create directory
file:
path: "{{item.mount_path}}"
state: directory
- name: Create a new primary partition
parted:
device: "{{item.drive}}"
number: 1
state: present
- name: Create an ext4 filesystem
filesystem:
fstype: ext4
dev: "{{item.drive}}{{item.partition_id}}"
- name: Mount drives
mount:
path: "{{item.mount_path}}"
src: "{{item.drive}}{{item.partition_id}}"
fstype: ext4
opts: noatime
state: mounted
When I’m running the main playbook I can see that include is loaded 3 times, and each task that is part of the “Disk Management” playbook is running 3 times
What am I missing?
Output:
TASK [Worker server disk format] ********************************************************************************************************************************************************
included: /data/ansible/cloudera-6.3.3-release/disk_management.yml for 10.201.51.36, 10.201.51.37, 10.201.51.38
included: /data/ansible/cloudera-6.3.3-release/disk_management.yml for 10.201.51.36, 10.201.51.37, 10.201.51.38
included: /data/ansible/cloudera-6.3.3-release/disk_management.yml for 10.201.51.36, 10.201.51.37, 10.201.51.38
TASK [create directory] *****************************************************************************************************************************************************************
changed: [10.201.51.36]
changed: [10.201.51.37]
changed: [10.201.51.38]
TASK [Create a new primary partition] ***************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Create an ext4 filesystem] ********************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Mount drives] *********************************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.37]
changed: [10.201.51.36]
TASK [create directory] *****************************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Create a new primary partition] ***************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Create an ext4 filesystem] ********************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.37]
changed: [10.201.51.36]
TASK [Mount drives] *********************************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [create directory] *****************************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Create a new primary partition] ***************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.36]
changed: [10.201.51.37]
TASK [Create an ext4 filesystem] ********************************************************************************************************************************************************
changed: [10.201.51.38]
changed: [10.201.51.37]
changed: [10.201.51.36]