Goal: Running the same task on different inventory group, each group with
different variables
Setup:
In my inventory hosts file, I have 2 groups. Web-Server and Manager
servers.
I have created a playbook that format and mounting disks, each group have a
different number of disks and different mount point name. Therefore I have
created VARs per group - but the tasks should be the same for the 2 groups.
How can I define the tasks to use the variables that are relevant to each
group? I have managed to run it a single group
Host file
[web_server]
130.1.1.1
130.1.1.2
130.1.1.3
[managr_server]
130.1.1.5
130.1.1.6
130.1.1.7
Playbook:
- hosts: all
become: true
vars:
web_server:
- {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}
manager_server:
- {drive: /dev/sdb ,mount_path: /manager1, partition_id: 1}
- {drive: /dev/sdc ,mount_path: /manager2, partition_id: 1}
tasks:
- name: create directory
file:
path: "{{item.mount_path}}"
state: directory
with_items: "{{web_server}}"
- name: Create a new primary partition
parted:
device: "{{item.drive}}"
number: 1
state: present
with_items: "{{web_server}}"
- name: Create a ext4 filesystem
filesystem:
fstype: ext4
dev: "{{item.drive}}{{item.partition_id}}"
with_items: "{{web_server}}"
- name: Mount drives
mount:
path: "{{item.mount_path}}"
src: "{{item.drive}}{{item.partition_id}}"
fstype: ext4
state: present
with_items: "{{web_server}}"
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/aa84666a-b3b3-41ca-b9b3-55de97d6f776%40googlegroups.com.