> 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
Systemic Ansible-way would be to create a role and use group_vars. For example 1) Keep the inventory (fix "manager_server" group label) 2) Create a role e.g. "manage_drives" with the tasks https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html a) Use ansible-galaxy to create an empty role $ ansible-galaxy init manage_drives b) Create tasks. tasks/main.yml - name: create directory file: path: "{{ item.mount_path }}" state: directory loop: "{{ my_drives }}" - name: Create a new primary partition parted: device: "{{item.drive}}" number: 1 state: present loop: "{{ my_drives }}" - name: Create a ext4 filesystem filesystem: fstype: ext4 dev: "{{ item.drive }}{{ item.partition_id }}" loop: "{{ my_drives }}" - name: Mount drives mount: path: "{{ item.mount_path }}" src: "{{ item.drive }}{{ item.partition_id }}" fstype: ext4 state: present loop: "{{ my_drives }" c) Review other artefacts of the role that you don't need right now (defaults, files, handlers, meta, templates, tests, vars). d) You might want to create empty list my_drives by default defaults/main.yml my_drives: [] 3) Create group_vars $ tree group_vars/ group_vars/ ├── manager_server.yml └── web_server.yml $ cat group_vars/manager_server.yml my_drives: - {drive: /dev/sdb ,mount_path: /manager1, partition_id: 1} - {drive: /dev/sdc ,mount_path: /manager2, partition_id: 1} $ cat group_vars/web_server.yml my_drives: - {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} 4) Create a playbook. Run it first with "--syntax-check" then with "--check". Then try it sharp. - hosts: manager_server become: true roles: - manage_drives - hosts: web_server become: true roles: - manage_drives HTH, -vlado -- 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/20200206100549.5b90590d%40gmail.com.
pgpWWZBXgDNct.pgp
Description: OpenPGP digital signature
