diff --git a/playbooks/deploy_vms_cluster.yaml b/playbooks/deploy_vms_cluster.yaml index 2fdcb090c..2ef8b77d4 100644 --- a/playbooks/deploy_vms_cluster.yaml +++ b/playbooks/deploy_vms_cluster.yaml @@ -9,9 +9,7 @@ gather_facts: false become: true tasks: - - name: "Deploy VMs" - include_tasks: tasks/deploy_vm.yaml - loop: "{{ groups['VMs'] }}" - - name: "Define colocation constraints" - include_tasks: tasks/colocation.yaml - loop: "{{ groups['VMs'] }}" + - name: Deploy VMs on Cluster Role + with_items: "{{ groups['VMs'] }}" + include_role: + name: deploy_vms_cluster diff --git a/playbooks/tasks/colocation.yaml b/playbooks/tasks/colocation.yaml deleted file mode 100644 index 0735b3be1..000000000 --- a/playbooks/tasks/colocation.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- name: "Define colocation constraints for {{ item }}" - cluster_vm: - name: "{{ item }}" - command: define_colocation - strong: "{{ hostvars[item].strong_colocation | default(false) }}" - colocated_vms: "{{ hostvars[item].colocated_vms }}" - when: hostvars[item].colocated_vms is defined diff --git a/playbooks/tasks/deploy_vm_from_template.yaml b/playbooks/tasks/deploy_vm_from_template.yaml deleted file mode 100644 index 91a43a628..000000000 --- a/playbooks/tasks/deploy_vm_from_template.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (C) 2021, RTE (http://www.rte-france.com) -# SPDX-License-Identifier: Apache-2.0 -# Task to deploy a VM from a template - ---- -- name: "Create {{ item }}" - cluster_vm: - name: "{{ item }}" - command: clone - src_name: "{{ template }}" - force: true - xml: "{{ lookup('file', vms_config_directory + '/' + item + '.xml') }}" - pinned_host: "{{ hostvars[item].pinned_host | default('') }}" - preferred_host: "{{ hostvars[item].preferred_host | default('') }}" diff --git a/roles/deploy_vms_cluster/README.md b/roles/deploy_vms_cluster/README.md new file mode 100644 index 000000000..900f4f322 --- /dev/null +++ b/roles/deploy_vms_cluster/README.md @@ -0,0 +1,21 @@ +# Deploy VMs on Cluster Seapath Role + +This role deploys Guests in cluster mode + +## Requirements + +no requirement. + +## Role Variables + +the role uses the "VMs" group in the inventory +and the following variables: +- qcow2tmpuploadfolder + +## Example Playbook + +```yaml +- hosts: cluster_machines + roles: + - { role: seapath_ansible.deploy_vms_cluster } +``` diff --git a/roles/deploy_vms_cluster/meta/main.yml b/roles/deploy_vms_cluster/meta/main.yml new file mode 100644 index 000000000..ea9bf9ad4 --- /dev/null +++ b/roles/deploy_vms_cluster/meta/main.yml @@ -0,0 +1,13 @@ +# Copyright (C) 2024 RTE +# SPDX-License-Identifier: Apache-2.0 +--- +galaxy_info: + author: "Seapath" + description: deploys Guests in cluster mode + license: Apache-2.0 + min_ansible_version: 2.9.10 + platforms: + - name: Linux + versions: + - all +dependencies: [] diff --git a/playbooks/tasks/deploy_vm.yaml b/roles/deploy_vms_cluster/tasks/main.yml similarity index 88% rename from playbooks/tasks/deploy_vm.yaml rename to roles/deploy_vms_cluster/tasks/main.yml index 2e77f6d35..5d25ab5f7 100644 --- a/playbooks/tasks/deploy_vm.yaml +++ b/roles/deploy_vms_cluster/tasks/main.yml @@ -1,7 +1,5 @@ -# Copyright (C) 2021, RTE (http://www.rte-france.com) -# Copyright (C) 2024 Savoir-faire Linux, Inc +# Copyright (C) 2024, RTE (http://www.rte-france.com) # SPDX-License-Identifier: Apache-2.0 -# Task to deploy a VM --- - name: "check presence of vm before copy" @@ -67,3 +65,11 @@ vm_file_dest: "{{ qcow2tmpuploadfolder | default('/tmp') + '/os.qcow2' }}" when: presencevm.status == "Undefined" or (hostvars[item].force is defined and hostvars[item].force) + +- name: "Define colocation constraints for {{ item }}" + cluster_vm: + name: "{{ item }}" + command: define_colocation + strong: "{{ hostvars[item].strong_colocation | default(false) }}" + colocated_vms: "{{ hostvars[item].colocated_vms }}" + when: hostvars[item].colocated_vms is defined