From 2c9d85e94a6f853fcc8e5a034c9e83896da5503c Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 21 Sep 2022 19:37:15 -0400 Subject: [PATCH] initial project commit --- README.md | 3 + galaxy.yml | 62 ++++++++++++++++ plugins/README.md | 31 ++++++++ roles/configure_vms/README.md | 38 ++++++++++ roles/configure_vms/defaults/main.yml | 2 + roles/configure_vms/handlers/main.yml | 2 + roles/configure_vms/meta/main.yml | 52 ++++++++++++++ roles/configure_vms/tasks/main.yml | 71 +++++++++++++++++++ .../templates/vm_config_lookup.j2 | 17 +++++ roles/configure_vms/tests/inventory | 2 + roles/configure_vms/tests/test.yml | 5 ++ roles/configure_vms/vars/main.yml | 2 + roles/create_ansible_inventory/README.md | 38 ++++++++++ .../defaults/main.yml | 2 + .../handlers/main.yml | 2 + roles/create_ansible_inventory/meta/main.yml | 52 ++++++++++++++ roles/create_ansible_inventory/tasks/main.yml | 26 +++++++ .../templates/ansible_inventory.j2 | 60 ++++++++++++++++ .../create_ansible_inventory/tests/inventory | 2 + roles/create_ansible_inventory/tests/test.yml | 5 ++ roles/create_ansible_inventory/vars/main.yml | 2 + roles/create_etc_hosts/README.md | 38 ++++++++++ roles/create_etc_hosts/defaults/main.yml | 2 + roles/create_etc_hosts/handlers/main.yml | 2 + roles/create_etc_hosts/meta/main.yml | 52 ++++++++++++++ roles/create_etc_hosts/tasks/main.yml | 26 +++++++ roles/create_etc_hosts/templates/etc_hosts.j2 | 18 +++++ roles/create_etc_hosts/tests/inventory | 2 + roles/create_etc_hosts/tests/test.yml | 5 ++ roles/create_etc_hosts/vars/main.yml | 2 + roles/create_snapshots/README.md | 38 ++++++++++ roles/create_snapshots/defaults/main.yml | 2 + roles/create_snapshots/handlers/main.yml | 2 + roles/create_snapshots/meta/main.yml | 52 ++++++++++++++ roles/create_snapshots/tasks/main.yml | 44 ++++++++++++ roles/create_snapshots/tests/inventory | 2 + roles/create_snapshots/tests/test.yml | 5 ++ roles/create_snapshots/vars/main.yml | 2 + roles/create_vms/README.md | 38 ++++++++++ roles/create_vms/defaults/main.yml | 2 + roles/create_vms/handlers/main.yml | 2 + roles/create_vms/meta/main.yml | 52 ++++++++++++++ roles/create_vms/tasks/main.yml | 45 ++++++++++++ roles/create_vms/tests/inventory | 2 + roles/create_vms/tests/test.yml | 5 ++ roles/create_vms/vars/main.yml | 2 + roles/destroy_vms/README.md | 38 ++++++++++ roles/destroy_vms/defaults/main.yml | 2 + roles/destroy_vms/handlers/main.yml | 2 + roles/destroy_vms/meta/main.yml | 52 ++++++++++++++ roles/destroy_vms/tasks/main.yml | 41 +++++++++++ roles/destroy_vms/tests/inventory | 2 + roles/destroy_vms/tests/test.yml | 5 ++ roles/destroy_vms/vars/main.yml | 2 + roles/generate_vmid/README.md | 38 ++++++++++ roles/generate_vmid/defaults/main.yml | 2 + roles/generate_vmid/handlers/main.yml | 2 + roles/generate_vmid/meta/main.yml | 52 ++++++++++++++ roles/generate_vmid/tasks/main.yml | 35 +++++++++ .../templates/generate_vmid_lookup.j2 | 13 ++++ roles/generate_vmid/tests/inventory | 2 + roles/generate_vmid/tests/test.yml | 5 ++ roles/generate_vmid/vars/main.yml | 2 + roles/get_vm_ipaddr/README.md | 38 ++++++++++ roles/get_vm_ipaddr/defaults/main.yml | 2 + roles/get_vm_ipaddr/handlers/main.yml | 2 + roles/get_vm_ipaddr/meta/main.yml | 52 ++++++++++++++ roles/get_vm_ipaddr/tasks/main.yml | 55 ++++++++++++++ .../templates/get_vm_ip_lookup.j2 | 19 +++++ roles/get_vm_ipaddr/tests/inventory | 2 + roles/get_vm_ipaddr/tests/test.yml | 5 ++ roles/get_vm_ipaddr/vars/main.yml | 2 + roles/rollback_vms/README.md | 38 ++++++++++ roles/rollback_vms/defaults/main.yml | 2 + roles/rollback_vms/handlers/main.yml | 2 + roles/rollback_vms/meta/main.yml | 52 ++++++++++++++ roles/rollback_vms/tasks/main.yml | 42 +++++++++++ roles/rollback_vms/tests/inventory | 2 + roles/rollback_vms/tests/test.yml | 5 ++ roles/rollback_vms/vars/main.yml | 2 + roles/shutdown_vms/README.md | 38 ++++++++++ roles/shutdown_vms/defaults/main.yml | 2 + roles/shutdown_vms/handlers/main.yml | 2 + roles/shutdown_vms/meta/main.yml | 52 ++++++++++++++ roles/shutdown_vms/tasks/main.yml | 41 +++++++++++ roles/shutdown_vms/tests/inventory | 2 + roles/shutdown_vms/tests/test.yml | 5 ++ roles/shutdown_vms/vars/main.yml | 2 + roles/ssh_keygen/README.md | 38 ++++++++++ roles/ssh_keygen/defaults/main.yml | 2 + roles/ssh_keygen/handlers/main.yml | 2 + roles/ssh_keygen/meta/main.yml | 52 ++++++++++++++ roles/ssh_keygen/tasks/main.yml | 9 +++ roles/ssh_keygen/tests/inventory | 2 + roles/ssh_keygen/tests/test.yml | 5 ++ roles/ssh_keygen/vars/main.yml | 2 + roles/start_vms/README.md | 38 ++++++++++ roles/start_vms/defaults/main.yml | 2 + roles/start_vms/handlers/main.yml | 2 + roles/start_vms/meta/main.yml | 52 ++++++++++++++ roles/start_vms/tasks/main.yml | 43 +++++++++++ roles/start_vms/tests/inventory | 2 + roles/start_vms/tests/test.yml | 5 ++ roles/start_vms/vars/main.yml | 2 + roles/stop_vms/README.md | 38 ++++++++++ roles/stop_vms/defaults/main.yml | 2 + roles/stop_vms/handlers/main.yml | 2 + roles/stop_vms/meta/main.yml | 52 ++++++++++++++ roles/stop_vms/tasks/main.yml | 41 +++++++++++ roles/stop_vms/tests/inventory | 2 + roles/stop_vms/tests/test.yml | 5 ++ roles/stop_vms/vars/main.yml | 2 + 112 files changed, 2081 insertions(+) create mode 100644 README.md create mode 100644 galaxy.yml create mode 100644 plugins/README.md create mode 100644 roles/configure_vms/README.md create mode 100644 roles/configure_vms/defaults/main.yml create mode 100644 roles/configure_vms/handlers/main.yml create mode 100644 roles/configure_vms/meta/main.yml create mode 100644 roles/configure_vms/tasks/main.yml create mode 100644 roles/configure_vms/templates/vm_config_lookup.j2 create mode 100644 roles/configure_vms/tests/inventory create mode 100644 roles/configure_vms/tests/test.yml create mode 100644 roles/configure_vms/vars/main.yml create mode 100644 roles/create_ansible_inventory/README.md create mode 100644 roles/create_ansible_inventory/defaults/main.yml create mode 100644 roles/create_ansible_inventory/handlers/main.yml create mode 100644 roles/create_ansible_inventory/meta/main.yml create mode 100644 roles/create_ansible_inventory/tasks/main.yml create mode 100644 roles/create_ansible_inventory/templates/ansible_inventory.j2 create mode 100644 roles/create_ansible_inventory/tests/inventory create mode 100644 roles/create_ansible_inventory/tests/test.yml create mode 100644 roles/create_ansible_inventory/vars/main.yml create mode 100644 roles/create_etc_hosts/README.md create mode 100644 roles/create_etc_hosts/defaults/main.yml create mode 100644 roles/create_etc_hosts/handlers/main.yml create mode 100644 roles/create_etc_hosts/meta/main.yml create mode 100644 roles/create_etc_hosts/tasks/main.yml create mode 100644 roles/create_etc_hosts/templates/etc_hosts.j2 create mode 100644 roles/create_etc_hosts/tests/inventory create mode 100644 roles/create_etc_hosts/tests/test.yml create mode 100644 roles/create_etc_hosts/vars/main.yml create mode 100644 roles/create_snapshots/README.md create mode 100644 roles/create_snapshots/defaults/main.yml create mode 100644 roles/create_snapshots/handlers/main.yml create mode 100644 roles/create_snapshots/meta/main.yml create mode 100644 roles/create_snapshots/tasks/main.yml create mode 100644 roles/create_snapshots/tests/inventory create mode 100644 roles/create_snapshots/tests/test.yml create mode 100644 roles/create_snapshots/vars/main.yml create mode 100644 roles/create_vms/README.md create mode 100644 roles/create_vms/defaults/main.yml create mode 100644 roles/create_vms/handlers/main.yml create mode 100644 roles/create_vms/meta/main.yml create mode 100644 roles/create_vms/tasks/main.yml create mode 100644 roles/create_vms/tests/inventory create mode 100644 roles/create_vms/tests/test.yml create mode 100644 roles/create_vms/vars/main.yml create mode 100644 roles/destroy_vms/README.md create mode 100644 roles/destroy_vms/defaults/main.yml create mode 100644 roles/destroy_vms/handlers/main.yml create mode 100644 roles/destroy_vms/meta/main.yml create mode 100644 roles/destroy_vms/tasks/main.yml create mode 100644 roles/destroy_vms/tests/inventory create mode 100644 roles/destroy_vms/tests/test.yml create mode 100644 roles/destroy_vms/vars/main.yml create mode 100644 roles/generate_vmid/README.md create mode 100644 roles/generate_vmid/defaults/main.yml create mode 100644 roles/generate_vmid/handlers/main.yml create mode 100644 roles/generate_vmid/meta/main.yml create mode 100644 roles/generate_vmid/tasks/main.yml create mode 100644 roles/generate_vmid/templates/generate_vmid_lookup.j2 create mode 100644 roles/generate_vmid/tests/inventory create mode 100644 roles/generate_vmid/tests/test.yml create mode 100644 roles/generate_vmid/vars/main.yml create mode 100644 roles/get_vm_ipaddr/README.md create mode 100644 roles/get_vm_ipaddr/defaults/main.yml create mode 100644 roles/get_vm_ipaddr/handlers/main.yml create mode 100644 roles/get_vm_ipaddr/meta/main.yml create mode 100644 roles/get_vm_ipaddr/tasks/main.yml create mode 100644 roles/get_vm_ipaddr/templates/get_vm_ip_lookup.j2 create mode 100644 roles/get_vm_ipaddr/tests/inventory create mode 100644 roles/get_vm_ipaddr/tests/test.yml create mode 100644 roles/get_vm_ipaddr/vars/main.yml create mode 100644 roles/rollback_vms/README.md create mode 100644 roles/rollback_vms/defaults/main.yml create mode 100644 roles/rollback_vms/handlers/main.yml create mode 100644 roles/rollback_vms/meta/main.yml create mode 100644 roles/rollback_vms/tasks/main.yml create mode 100644 roles/rollback_vms/tests/inventory create mode 100644 roles/rollback_vms/tests/test.yml create mode 100644 roles/rollback_vms/vars/main.yml create mode 100644 roles/shutdown_vms/README.md create mode 100644 roles/shutdown_vms/defaults/main.yml create mode 100644 roles/shutdown_vms/handlers/main.yml create mode 100644 roles/shutdown_vms/meta/main.yml create mode 100644 roles/shutdown_vms/tasks/main.yml create mode 100644 roles/shutdown_vms/tests/inventory create mode 100644 roles/shutdown_vms/tests/test.yml create mode 100644 roles/shutdown_vms/vars/main.yml create mode 100644 roles/ssh_keygen/README.md create mode 100644 roles/ssh_keygen/defaults/main.yml create mode 100644 roles/ssh_keygen/handlers/main.yml create mode 100644 roles/ssh_keygen/meta/main.yml create mode 100644 roles/ssh_keygen/tasks/main.yml create mode 100644 roles/ssh_keygen/tests/inventory create mode 100644 roles/ssh_keygen/tests/test.yml create mode 100644 roles/ssh_keygen/vars/main.yml create mode 100644 roles/start_vms/README.md create mode 100644 roles/start_vms/defaults/main.yml create mode 100644 roles/start_vms/handlers/main.yml create mode 100644 roles/start_vms/meta/main.yml create mode 100644 roles/start_vms/tasks/main.yml create mode 100644 roles/start_vms/tests/inventory create mode 100644 roles/start_vms/tests/test.yml create mode 100644 roles/start_vms/vars/main.yml create mode 100644 roles/stop_vms/README.md create mode 100644 roles/stop_vms/defaults/main.yml create mode 100644 roles/stop_vms/handlers/main.yml create mode 100644 roles/stop_vms/meta/main.yml create mode 100644 roles/stop_vms/tasks/main.yml create mode 100644 roles/stop_vms/tests/inventory create mode 100644 roles/stop_vms/tests/test.yml create mode 100644 roles/stop_vms/vars/main.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5cace8 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Ansible Collection - jchristianh.pve + +Documentation for the collection. diff --git a/galaxy.yml b/galaxy.yml new file mode 100644 index 0000000..424dd9d --- /dev/null +++ b/galaxy.yml @@ -0,0 +1,62 @@ +### REQUIRED +# The namespace of the collection. This can be a company/brand/organization or product namespace under which all +# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with +# underscores or numbers and cannot contain consecutive underscores +namespace: jchristianh + +# The name of the collection. Has the same character restrictions as 'namespace' +name: pve + +# The version of the collection. Must be compatible with semantic versioning +version: 1.0.0 + +# The path to the Markdown (.md) readme file. This path is relative to the root of the collection +readme: README.md + +# A list of the collection's content authors. Can be just the name or in the format 'Full Name (url) +# @nicks:irc/im.site#channel' +authors: +- your name + + +### OPTIONAL but strongly recommended +# A short summary description of the collection +description: your collection description + +# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only +# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' +license: +- GPL-2.0-or-later + +# The path to the license file for the collection. This path is relative to the root of the collection. This key is +# mutually exclusive with 'license' +license_file: '' + +# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character +# requirements as 'namespace' and 'name' +tags: [] + +# Collections that this collection requires to be installed for it to be usable. The key of the dict is the +# collection label 'namespace.name'. The value is a version range +# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version +# range specifiers can be set and are separated by ',' +dependencies: {} + +# The URL of the originating SCM repository +repository: http://example.com/repository + +# The URL to any online docs +documentation: http://docs.example.com + +# The URL to the homepage of the collection/project +homepage: http://example.com + +# The URL to the collection issue tracker +issues: http://example.com/issue/tracker + +# A list of file glob-like patterns used to filter any files or directories that should not be included in the build +# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This +# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', +# and '.git' are always filtered +build_ignore: [] + diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..775d977 --- /dev/null +++ b/plugins/README.md @@ -0,0 +1,31 @@ +# Collections Plugins Directory + +This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that +is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that +would contain module utils and modules respectively. + +Here is an example directory of the majority of plugins currently supported by Ansible: + +``` +└── plugins + ├── action + ├── become + ├── cache + ├── callback + ├── cliconf + ├── connection + ├── filter + ├── httpapi + ├── inventory + ├── lookup + ├── module_utils + ├── modules + ├── netconf + ├── shell + ├── strategy + ├── terminal + ├── test + └── vars +``` + +A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible-core/2.12/plugins/plugins.html). diff --git a/roles/configure_vms/README.md b/roles/configure_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/configure_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/configure_vms/defaults/main.yml b/roles/configure_vms/defaults/main.yml new file mode 100644 index 0000000..afac173 --- /dev/null +++ b/roles/configure_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for configure_vms diff --git a/roles/configure_vms/handlers/main.yml b/roles/configure_vms/handlers/main.yml new file mode 100644 index 0000000..86f1442 --- /dev/null +++ b/roles/configure_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for configure_vms diff --git a/roles/configure_vms/meta/main.yml b/roles/configure_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/configure_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/configure_vms/tasks/main.yml b/roles/configure_vms/tasks/main.yml new file mode 100644 index 0000000..ae94f48 --- /dev/null +++ b/roles/configure_vms/tasks/main.yml @@ -0,0 +1,71 @@ +--- +- name: Wait for VM creation... + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_wait_for_vm + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_wait_for_vm.status == 200 and r_wait_for_vm.json.data.status is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Get current VM configuration + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/config" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_get_vm_config + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_get_vm_config.status == 200 and r_get_vm_config.json.data.net0 is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Process configuration data + set_fact: + r_setup_config_data: "{{ lookup('template', 'vm_config_lookup.j2') }}" + + +- name: Configure VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/config" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + body_format : form-urlencoded + body : + vmid : "{{ item.vmid }}" + cores : "{{ item.cores | default(__lab_cores_default) }}" + memory : "{{ '{0:0.0f}'.format(item.mem|default(__lab_mem_default) * 1024)|int }}" + net0 : "virtio={{ item.mac_addr}},bridge={{ __lab_bridge }},tag={{ __lab_vlan }}" + return_content : no + validate_certs : no + register : r_config_vm + loop : "{{ r_setup_config_data }}" + loop_control : + label : "{{ item.name }}" + when : + - item.status == 'stopped'|lower + + +... diff --git a/roles/configure_vms/templates/vm_config_lookup.j2 b/roles/configure_vms/templates/vm_config_lookup.j2 new file mode 100644 index 0000000..f57752e --- /dev/null +++ b/roles/configure_vms/templates/vm_config_lookup.j2 @@ -0,0 +1,17 @@ +[ +{% for vm_wait in r_wait_for_vm.results %} +{% for vm_config in r_get_vm_config.results %} +{% if vm_wait.item.name == vm_config.item.name %} +{ + "name" : "{{ vm_config.item.name }}", + "vmid" : "{{ vm_config.item.vmid }}", + "vm_host" : "{{ vm_config.item.vm_host }}", + "status" : "{{ vm_wait.json.data.status }}", + "cores" : "{{ vm_config.item.cores }}", + "mem" : {{ vm_config.item.mem }}, + "mac_addr" : "{{ vm_config.json.data.net0 | regex_replace('^virtio=(.*),bridge=.*$','\\1') }}", +}, +{% endif %} +{% endfor %} +{% endfor %} +] diff --git a/roles/configure_vms/tests/inventory b/roles/configure_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/configure_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/configure_vms/tests/test.yml b/roles/configure_vms/tests/test.yml new file mode 100644 index 0000000..6f68df1 --- /dev/null +++ b/roles/configure_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - configure_vms diff --git a/roles/configure_vms/vars/main.yml b/roles/configure_vms/vars/main.yml new file mode 100644 index 0000000..cafc261 --- /dev/null +++ b/roles/configure_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for configure_vms diff --git a/roles/create_ansible_inventory/README.md b/roles/create_ansible_inventory/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/create_ansible_inventory/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/create_ansible_inventory/defaults/main.yml b/roles/create_ansible_inventory/defaults/main.yml new file mode 100644 index 0000000..6f08458 --- /dev/null +++ b/roles/create_ansible_inventory/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for create_ansible_inventory diff --git a/roles/create_ansible_inventory/handlers/main.yml b/roles/create_ansible_inventory/handlers/main.yml new file mode 100644 index 0000000..cb2ebdd --- /dev/null +++ b/roles/create_ansible_inventory/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for create_ansible_inventory diff --git a/roles/create_ansible_inventory/meta/main.yml b/roles/create_ansible_inventory/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/create_ansible_inventory/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/create_ansible_inventory/tasks/main.yml b/roles/create_ansible_inventory/tasks/main.yml new file mode 100644 index 0000000..320161c --- /dev/null +++ b/roles/create_ansible_inventory/tasks/main.yml @@ -0,0 +1,26 @@ +--- +- name: Create inventory for Environment + block: + - name: Write inventory + template : + src : "{{ lab_inv_tmpl }}" + dest : "{{ lab_inv_dest }}/{{ lab_inv_file }}" + + rescue: + - name: Pause for 10s + pause: + seconds: 10 + + + - name: Fetch VM info + include_role: + name: jchristianh.pve.get_vm_ipaddr + + + - name: Write inventory + template : + src : "{{ lab_inv_tmpl }}" + dest : "{{ lab_inv_dest }}/{{ lab_inv_file }}" + + +... diff --git a/roles/create_ansible_inventory/templates/ansible_inventory.j2 b/roles/create_ansible_inventory/templates/ansible_inventory.j2 new file mode 100644 index 0000000..8f7a38b --- /dev/null +++ b/roles/create_ansible_inventory/templates/ansible_inventory.j2 @@ -0,0 +1,60 @@ +# {{ lab_template_header }} Inventory +################################################# +# +# Configuration : {{ lab_inv_file }} +# Template Version : {{ lab_inv_ver }}-{{ lab_inv_rev }} +# +# {{ __project_maintainer }} <{{ __project_maintainer_email }}> +################################################# + + +######################### +# Environment Overview # +# -------------------- # +# KEY: # +# Node :: Group :: IP # +######################### +{% for node in r_hosts_inventory %} +# {{ node.name }} :: {{ node.group }} :: {{ node.address }} :: {{ node.vm_host }} +{% endfor %} + + + +################### +### HOST GROUPS ### +################### +{% for group in lab_groups %} +[{{ group }}] +{% for node in r_hosts_inventory %} +{% if node.group == group %} +{{ node.name }} ansible_host={{ node.address }} +{% endif %} +{% endfor %} + +{% endfor %} + + +{% if lab_parents is defined %} +################# +### SUBGROUPS ### +################# +{% for parent in lab_parents %} +[{{ parent }}:children] +{% for group in lab_parents[parent].groups %} +{{ group }} +{% endfor %} + +[{{ parent }}:vars] +{% for var in lab_parents[parent].vars %} +{{ var }} +{% endfor %} + +{% endfor %} +{% endif %} + + +# vars for all hosts/groups +[all:vars] +{% if __use_bastion is defined and __use_bastion|bool %} +ansible_ssh_common_args='-J {{ __bastion_user }}@{{ __bastion_host }}' +{% endif %} diff --git a/roles/create_ansible_inventory/tests/inventory b/roles/create_ansible_inventory/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/create_ansible_inventory/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/create_ansible_inventory/tests/test.yml b/roles/create_ansible_inventory/tests/test.yml new file mode 100644 index 0000000..3ecf35e --- /dev/null +++ b/roles/create_ansible_inventory/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - create_ansible_inventory diff --git a/roles/create_ansible_inventory/vars/main.yml b/roles/create_ansible_inventory/vars/main.yml new file mode 100644 index 0000000..b08e6be --- /dev/null +++ b/roles/create_ansible_inventory/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for create_ansible_inventory diff --git a/roles/create_etc_hosts/README.md b/roles/create_etc_hosts/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/create_etc_hosts/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/create_etc_hosts/defaults/main.yml b/roles/create_etc_hosts/defaults/main.yml new file mode 100644 index 0000000..c4dd24c --- /dev/null +++ b/roles/create_etc_hosts/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for create_etc_hosts diff --git a/roles/create_etc_hosts/handlers/main.yml b/roles/create_etc_hosts/handlers/main.yml new file mode 100644 index 0000000..82fcc12 --- /dev/null +++ b/roles/create_etc_hosts/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for create_etc_hosts diff --git a/roles/create_etc_hosts/meta/main.yml b/roles/create_etc_hosts/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/create_etc_hosts/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/create_etc_hosts/tasks/main.yml b/roles/create_etc_hosts/tasks/main.yml new file mode 100644 index 0000000..cabd56a --- /dev/null +++ b/roles/create_etc_hosts/tasks/main.yml @@ -0,0 +1,26 @@ +--- +- name: Create /etc/hosts for Environment + block: + - name: "Write /etc/hosts file to {{ etc_hosts_dest }}" + template : + src : "{{ etc_hosts_tmpl }}" + dest : "{{ etc_hosts_dest }}" + + rescue: + - name: Pause for 10s + pause: + seconds: 10 + + + - name: Fetch VM info + include_role: + name: jchristianh.pve.get_vm_ipaddr + + + - name: "Write /etc/hosts file to {{ etc_hosts_dest }}" + template : + src : "{{ etc_hosts_tmpl }}" + dest : "{{ etc_hosts_dest }}" + + +... diff --git a/roles/create_etc_hosts/templates/etc_hosts.j2 b/roles/create_etc_hosts/templates/etc_hosts.j2 new file mode 100644 index 0000000..d2de252 --- /dev/null +++ b/roles/create_etc_hosts/templates/etc_hosts.j2 @@ -0,0 +1,18 @@ +# {{ template_run_date }} +################################ +# {{ lab_template_header }} # +################################ +# +# Configuration : {{ etc_hosts_file }} +# Template Version : {{ etc_hosts_ver }}-{{ etc_hosts_rev }} +# +# {{ __project_maintainer }} <{{ __project_maintainer_email }}> +################################################# + +127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 +::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 + + +{% for node in r_hosts_inventory %} +{{ node.address }} {{ node.name }} {{ node.name }}.{{ __pve_tld }} +{% endfor %} diff --git a/roles/create_etc_hosts/tests/inventory b/roles/create_etc_hosts/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/create_etc_hosts/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/create_etc_hosts/tests/test.yml b/roles/create_etc_hosts/tests/test.yml new file mode 100644 index 0000000..4c34e8b --- /dev/null +++ b/roles/create_etc_hosts/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - create_etc_hosts diff --git a/roles/create_etc_hosts/vars/main.yml b/roles/create_etc_hosts/vars/main.yml new file mode 100644 index 0000000..adf0e42 --- /dev/null +++ b/roles/create_etc_hosts/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for create_etc_hosts diff --git a/roles/create_snapshots/README.md b/roles/create_snapshots/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/create_snapshots/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/create_snapshots/defaults/main.yml b/roles/create_snapshots/defaults/main.yml new file mode 100644 index 0000000..c4cc303 --- /dev/null +++ b/roles/create_snapshots/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for create_snapshots diff --git a/roles/create_snapshots/handlers/main.yml b/roles/create_snapshots/handlers/main.yml new file mode 100644 index 0000000..8bdd9d6 --- /dev/null +++ b/roles/create_snapshots/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for create_snapshots diff --git a/roles/create_snapshots/meta/main.yml b/roles/create_snapshots/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/create_snapshots/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/create_snapshots/tasks/main.yml b/roles/create_snapshots/tasks/main.yml new file mode 100644 index 0000000..e59f05d --- /dev/null +++ b/roles/create_snapshots/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Check if desired snapshot exists in PVE + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/snapshot/{{ __lab_snapshot_name }}/config" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + status_code : + - 200 + - 500 + register : r_snapshot_list + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + + +- name: Create VM snapshot if one doesn't exist + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/{{ item.item.vmid }}/snapshot" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + body_format : form-urlencoded + body : + node : "{{ item.item.vm_host | default(__pve_node) }}" + vmid : "{{ item.item.vmid }}" + snapname : "{{ __lab_snapshot_name }}" + return_content : no + validate_certs : no + register : r_snapshot_create + loop : "{{ r_snapshot_list.results }}" + loop_control : + label : "[{{ item.item.vmid }}] {{ item.item.name }}" + when : + - item.msg is search("Error") + + +... diff --git a/roles/create_snapshots/tests/inventory b/roles/create_snapshots/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/create_snapshots/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/create_snapshots/tests/test.yml b/roles/create_snapshots/tests/test.yml new file mode 100644 index 0000000..20f88c4 --- /dev/null +++ b/roles/create_snapshots/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - create_snapshots diff --git a/roles/create_snapshots/vars/main.yml b/roles/create_snapshots/vars/main.yml new file mode 100644 index 0000000..4777bca --- /dev/null +++ b/roles/create_snapshots/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for create_snapshots diff --git a/roles/create_vms/README.md b/roles/create_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/create_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/create_vms/defaults/main.yml b/roles/create_vms/defaults/main.yml new file mode 100644 index 0000000..4dc7ed9 --- /dev/null +++ b/roles/create_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for create_vms diff --git a/roles/create_vms/handlers/main.yml b/roles/create_vms/handlers/main.yml new file mode 100644 index 0000000..0aa2992 --- /dev/null +++ b/roles/create_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for create_vms diff --git a/roles/create_vms/meta/main.yml b/roles/create_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/create_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/create_vms/tasks/main.yml b/roles/create_vms/tasks/main.yml new file mode 100644 index 0000000..c0bbd74 --- /dev/null +++ b/roles/create_vms/tasks/main.yml @@ -0,0 +1,45 @@ +--- +- name: Fetch VM list from API + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/config" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + return_content : no + validate_certs : no + status_code : + - 200 + - 500 + register : r_get_vm_list + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + + +- name: Create VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ __pve_node }}/qemu/\ + {{ item.item.vm_template_id | default(__vm_tmpl_id) }}/clone" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + body_format : form-urlencoded + body: + vmid : "{{ item.item.vm_template_id | default(__vm_tmpl_id) }}" + newid : "{{ item.item.vmid }}" + name : "{{ item.item.name }}" + target : "{{ item.item.vm_host | default(__pve_node) }}" + return_content : no + validate_certs : no + register : r_create_vm + loop : "{{ r_get_vm_list.results }}" + loop_control : + label : "{{ item.item.name }}" + when : + - item.status == 500 + + +... diff --git a/roles/create_vms/tests/inventory b/roles/create_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/create_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/create_vms/tests/test.yml b/roles/create_vms/tests/test.yml new file mode 100644 index 0000000..e095bc2 --- /dev/null +++ b/roles/create_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - create_vms diff --git a/roles/create_vms/vars/main.yml b/roles/create_vms/vars/main.yml new file mode 100644 index 0000000..7cd1ded --- /dev/null +++ b/roles/create_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for create_vms diff --git a/roles/destroy_vms/README.md b/roles/destroy_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/destroy_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/destroy_vms/defaults/main.yml b/roles/destroy_vms/defaults/main.yml new file mode 100644 index 0000000..8a7b228 --- /dev/null +++ b/roles/destroy_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for destroy_vms diff --git a/roles/destroy_vms/handlers/main.yml b/roles/destroy_vms/handlers/main.yml new file mode 100644 index 0000000..5a3f13c --- /dev/null +++ b/roles/destroy_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for destroy_vms diff --git a/roles/destroy_vms/meta/main.yml b/roles/destroy_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/destroy_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/destroy_vms/tasks/main.yml b/roles/destroy_vms/tasks/main.yml new file mode 100644 index 0000000..56a418c --- /dev/null +++ b/roles/destroy_vms/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: Verify VM status + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + return_content : no + validate_certs : no + register : r_wait_status + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_wait_status.json.data.status == 'stopped'|lower + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Destroy VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/{{ item.item.vmid }}" + method : DELETE + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + vmid : "{{ item.item.vmid }}" + return_content : no + validate_certs : no + register : r_delete_vm + loop : "{{ r_wait_status.results }}" + loop_control : + label : "{{ item.json.data.name }}" + when : + - item.json.data is defined + - item.json.data.status == 'stopped'|lower + + +... diff --git a/roles/destroy_vms/tests/inventory b/roles/destroy_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/destroy_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/destroy_vms/tests/test.yml b/roles/destroy_vms/tests/test.yml new file mode 100644 index 0000000..624fdd2 --- /dev/null +++ b/roles/destroy_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - destroy_vms diff --git a/roles/destroy_vms/vars/main.yml b/roles/destroy_vms/vars/main.yml new file mode 100644 index 0000000..4fdf5c1 --- /dev/null +++ b/roles/destroy_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for destroy_vms diff --git a/roles/generate_vmid/README.md b/roles/generate_vmid/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/generate_vmid/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/generate_vmid/defaults/main.yml b/roles/generate_vmid/defaults/main.yml new file mode 100644 index 0000000..c67cd52 --- /dev/null +++ b/roles/generate_vmid/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for generate_vmid diff --git a/roles/generate_vmid/handlers/main.yml b/roles/generate_vmid/handlers/main.yml new file mode 100644 index 0000000..61ba405 --- /dev/null +++ b/roles/generate_vmid/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for generate_vmid diff --git a/roles/generate_vmid/meta/main.yml b/roles/generate_vmid/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/generate_vmid/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/generate_vmid/tasks/main.yml b/roles/generate_vmid/tasks/main.yml new file mode 100644 index 0000000..e186f5f --- /dev/null +++ b/roles/generate_vmid/tasks/main.yml @@ -0,0 +1,35 @@ +--- +#- name: Generate and associate VMID to VM +# set_fact : +# lab_nodes : +# "{{ lab_nodes | combine({ item.name: {'vmid': lab_vmid_base + idx_lab_nodes} }, recursive=True) }}" +# loop : "{{ lab_nodes }}" +# loop_control : +# label : "{{ item.name }}" +# index_var : idx_lab_nodes + + +#- name: Debug lab_nodes +# debug : +# var : lab_nodes + + +- name: Generate and associate VMID to VM + set_fact: + lab_nodes: "{{ lookup('template', 'generate_vmid_lookup.j2') }}" + + +#- name: Debug lab_nodes +# debug : +# var : lab_nodes + + +#- name: Debug lab_nodes again +# debug : +# msg : "{{ item.name }} -> {{ item.vmid }}" +# loop: "{{ lab_nodes }}" +# loop_control: +# label: "{{ item.name }}" + + +... diff --git a/roles/generate_vmid/templates/generate_vmid_lookup.j2 b/roles/generate_vmid/templates/generate_vmid_lookup.j2 new file mode 100644 index 0000000..52373ff --- /dev/null +++ b/roles/generate_vmid/templates/generate_vmid_lookup.j2 @@ -0,0 +1,13 @@ +[ +{% for lab_node in lab_nodes %} + { + "name" : "{{ lab_node.name }}", + "vmid" : "{{ lab_vmid_base + (loop.index - 1) }}", + "vm_host" : "{{ lab_node.vm_host | default(__pve_node) }}", + "vm_template_id" : "{{ lab_node.vm_template_id | default(__vm_tmpl_id) }}", + "group" : "{{ lab_node.group | default(__default_inventory_group) }}", + "cores" : "{{ lab_node.cores | default(__lab_cores_default) }}", + "mem" : {{ lab_node.mem | default(__lab_mem_default) }}, + }, +{% endfor %} +] diff --git a/roles/generate_vmid/tests/inventory b/roles/generate_vmid/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/generate_vmid/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/generate_vmid/tests/test.yml b/roles/generate_vmid/tests/test.yml new file mode 100644 index 0000000..c25a26a --- /dev/null +++ b/roles/generate_vmid/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - generate_vmid diff --git a/roles/generate_vmid/vars/main.yml b/roles/generate_vmid/vars/main.yml new file mode 100644 index 0000000..67f452d --- /dev/null +++ b/roles/generate_vmid/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for generate_vmid diff --git a/roles/get_vm_ipaddr/README.md b/roles/get_vm_ipaddr/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/get_vm_ipaddr/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/get_vm_ipaddr/defaults/main.yml b/roles/get_vm_ipaddr/defaults/main.yml new file mode 100644 index 0000000..bfb262b --- /dev/null +++ b/roles/get_vm_ipaddr/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for get_vm_ipaddr diff --git a/roles/get_vm_ipaddr/handlers/main.yml b/roles/get_vm_ipaddr/handlers/main.yml new file mode 100644 index 0000000..7216880 --- /dev/null +++ b/roles/get_vm_ipaddr/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for get_vm_ipaddr diff --git a/roles/get_vm_ipaddr/meta/main.yml b/roles/get_vm_ipaddr/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/get_vm_ipaddr/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/get_vm_ipaddr/tasks/main.yml b/roles/get_vm_ipaddr/tasks/main.yml new file mode 100644 index 0000000..34144ce --- /dev/null +++ b/roles/get_vm_ipaddr/tasks/main.yml @@ -0,0 +1,55 @@ +--- +- name: Get network info from API + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/agent/network-get-interfaces" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_network_interfaces + loop : "{{ lab_nodes }}" + loop_control: + label : "{{ item.name }}" + until : r_network_interfaces.status == 200 + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Process API information + block: + - name: Process results from API + set_fact: + r_hosts_inventory: "{{ lookup('template', 'get_vm_ip_lookup.j2') }}" + + + rescue: + - name: Retry fetching network info from API + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/agent/network-get-interfaces" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + node : "{{ item.vm_host | default(__pve_node) }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_network_interfaces + loop : "{{ lab_nodes }}" + loop_control: + label : "{{ item.name }}" + until : r_network_interfaces.status == 200 + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + + - name: Process results from API + set_fact: + r_hosts_inventory: "{{ lookup('template', 'get_vm_ip_lookup.j2') }}" + + +... diff --git a/roles/get_vm_ipaddr/templates/get_vm_ip_lookup.j2 b/roles/get_vm_ipaddr/templates/get_vm_ip_lookup.j2 new file mode 100644 index 0000000..289c543 --- /dev/null +++ b/roles/get_vm_ipaddr/templates/get_vm_ip_lookup.j2 @@ -0,0 +1,19 @@ +[ +{% for node in r_network_interfaces.results %} + { + "name" : "{{ node.item.name }}", + "vmid" : "{{ node.item.vmid }}", + "vm_host" : "{{ node.item.vm_host | default(__pve_node) }}", + "group" : "{{ node.item.group }}", +{% for interfaces in node.json.data.result %} +{% if interfaces.name != 'lo' %} +{% for addr in interfaces["ip-addresses"] %} +{% if addr["ip-address-type"] == "ipv4" %} + "address" : "{{ addr["ip-address"] }}", +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} + }, +{% endfor %} +] diff --git a/roles/get_vm_ipaddr/tests/inventory b/roles/get_vm_ipaddr/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/get_vm_ipaddr/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/get_vm_ipaddr/tests/test.yml b/roles/get_vm_ipaddr/tests/test.yml new file mode 100644 index 0000000..ad2d31a --- /dev/null +++ b/roles/get_vm_ipaddr/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - get_vm_ipaddr diff --git a/roles/get_vm_ipaddr/vars/main.yml b/roles/get_vm_ipaddr/vars/main.yml new file mode 100644 index 0000000..b6e5d7c --- /dev/null +++ b/roles/get_vm_ipaddr/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for get_vm_ipaddr diff --git a/roles/rollback_vms/README.md b/roles/rollback_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/rollback_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/rollback_vms/defaults/main.yml b/roles/rollback_vms/defaults/main.yml new file mode 100644 index 0000000..5bf3c21 --- /dev/null +++ b/roles/rollback_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for rollback_vms diff --git a/roles/rollback_vms/handlers/main.yml b/roles/rollback_vms/handlers/main.yml new file mode 100644 index 0000000..feb73d2 --- /dev/null +++ b/roles/rollback_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for rollback_vms diff --git a/roles/rollback_vms/meta/main.yml b/roles/rollback_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/rollback_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/rollback_vms/tasks/main.yml b/roles/rollback_vms/tasks/main.yml new file mode 100644 index 0000000..cefbb95 --- /dev/null +++ b/roles/rollback_vms/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- name: Rollback VMs to initial state + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/{{ item.vmid }}/snapshot/{{ __lab_snapshot_name }}/rollback" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + body_format : form-urlencoded + body: + node : "{{ item.vm_host | default(__pve_node) }}" + vmid : "{{ item.vmid }}" + snapname : "{{ __lab_snapshot_name }}" + return_content : no + validate_certs : no + register : r_rollback_vms + loop : "{{ lab_nodes }}" + loop_control : + label : "[{{ item.vmid }}] {{ item.name }}" + + +- name: Wait for rollback completion... + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_wait_for_rollback + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_wait_for_rollback.status == 200 and r_wait_for_rollback.json.data.status is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +... diff --git a/roles/rollback_vms/tests/inventory b/roles/rollback_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/rollback_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/rollback_vms/tests/test.yml b/roles/rollback_vms/tests/test.yml new file mode 100644 index 0000000..4b88321 --- /dev/null +++ b/roles/rollback_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - rollback_vms diff --git a/roles/rollback_vms/vars/main.yml b/roles/rollback_vms/vars/main.yml new file mode 100644 index 0000000..0cfdd3d --- /dev/null +++ b/roles/rollback_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for rollback_vms diff --git a/roles/shutdown_vms/README.md b/roles/shutdown_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/shutdown_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/shutdown_vms/defaults/main.yml b/roles/shutdown_vms/defaults/main.yml new file mode 100644 index 0000000..e37f3b2 --- /dev/null +++ b/roles/shutdown_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for shutdown_vms diff --git a/roles/shutdown_vms/handlers/main.yml b/roles/shutdown_vms/handlers/main.yml new file mode 100644 index 0000000..bcf87db --- /dev/null +++ b/roles/shutdown_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for shutdown_vms diff --git a/roles/shutdown_vms/meta/main.yml b/roles/shutdown_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/shutdown_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/shutdown_vms/tasks/main.yml b/roles/shutdown_vms/tasks/main.yml new file mode 100644 index 0000000..9d0d8d2 --- /dev/null +++ b/roles/shutdown_vms/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: Fetch VM status + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_fetch_status + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_fetch_status.status == 200 and r_fetch_status.json.data.status is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Shutdown VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.item.vmid }}/status/shutdown" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.item.vmid }}" + return_content : no + validate_certs : no + register : r_start_vm + loop : "{{ r_fetch_status.results }}" + loop_control : + label : "{{ item.json.data.name }}" + when : + - item.json.data.status == 'running'|lower + + +... diff --git a/roles/shutdown_vms/tests/inventory b/roles/shutdown_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/shutdown_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/shutdown_vms/tests/test.yml b/roles/shutdown_vms/tests/test.yml new file mode 100644 index 0000000..fb3b2df --- /dev/null +++ b/roles/shutdown_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - shutdown_vms diff --git a/roles/shutdown_vms/vars/main.yml b/roles/shutdown_vms/vars/main.yml new file mode 100644 index 0000000..75c8cc1 --- /dev/null +++ b/roles/shutdown_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for shutdown_vms diff --git a/roles/ssh_keygen/README.md b/roles/ssh_keygen/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/ssh_keygen/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/ssh_keygen/defaults/main.yml b/roles/ssh_keygen/defaults/main.yml new file mode 100644 index 0000000..acb68e0 --- /dev/null +++ b/roles/ssh_keygen/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for ssh_keygen diff --git a/roles/ssh_keygen/handlers/main.yml b/roles/ssh_keygen/handlers/main.yml new file mode 100644 index 0000000..21ec303 --- /dev/null +++ b/roles/ssh_keygen/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for ssh_keygen diff --git a/roles/ssh_keygen/meta/main.yml b/roles/ssh_keygen/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/ssh_keygen/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/ssh_keygen/tasks/main.yml b/roles/ssh_keygen/tasks/main.yml new file mode 100644 index 0000000..a1e1386 --- /dev/null +++ b/roles/ssh_keygen/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Generate SSH keypair for Environment + community.crypto.openssh_keypair: + path: "{{ __ssh_keypair_dest }}/{{ __ssh_keypair_name }}" + type: "{{ __ssh_keypair_type }}" + size: "{{ __ssh_keypair_size|int }}" + + +... diff --git a/roles/ssh_keygen/tests/inventory b/roles/ssh_keygen/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/ssh_keygen/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/ssh_keygen/tests/test.yml b/roles/ssh_keygen/tests/test.yml new file mode 100644 index 0000000..1c64ff7 --- /dev/null +++ b/roles/ssh_keygen/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ssh_keygen diff --git a/roles/ssh_keygen/vars/main.yml b/roles/ssh_keygen/vars/main.yml new file mode 100644 index 0000000..b4a2ae0 --- /dev/null +++ b/roles/ssh_keygen/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for ssh_keygen diff --git a/roles/start_vms/README.md b/roles/start_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/start_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/start_vms/defaults/main.yml b/roles/start_vms/defaults/main.yml new file mode 100644 index 0000000..1070d26 --- /dev/null +++ b/roles/start_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for start_vms diff --git a/roles/start_vms/handlers/main.yml b/roles/start_vms/handlers/main.yml new file mode 100644 index 0000000..b1d6654 --- /dev/null +++ b/roles/start_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for start_vms diff --git a/roles/start_vms/meta/main.yml b/roles/start_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/start_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/start_vms/tasks/main.yml b/roles/start_vms/tasks/main.yml new file mode 100644 index 0000000..416e20e --- /dev/null +++ b/roles/start_vms/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: Fetch VM status + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_fetch_status + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_fetch_status.status == 200 and r_fetch_status.json.data.status is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Start VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.item.vmid }}/status/start" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.item.vmid }}" + return_content : no + validate_certs : no + register : r_start_vm + loop : "{{ r_fetch_status.results }}" + loop_control : + label : "{{ item.json.data.name }}" + pause : "{{ __vm_start_delay }}" # pause added to prevent i/o overload + # on larger labs + when : + - item.json.data.status == 'stopped'|lower + + +... diff --git a/roles/start_vms/tests/inventory b/roles/start_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/start_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/start_vms/tests/test.yml b/roles/start_vms/tests/test.yml new file mode 100644 index 0000000..9461c9e --- /dev/null +++ b/roles/start_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - start_vms diff --git a/roles/start_vms/vars/main.yml b/roles/start_vms/vars/main.yml new file mode 100644 index 0000000..ec61a13 --- /dev/null +++ b/roles/start_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for start_vms diff --git a/roles/stop_vms/README.md b/roles/stop_vms/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/stop_vms/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/stop_vms/defaults/main.yml b/roles/stop_vms/defaults/main.yml new file mode 100644 index 0000000..f9c3278 --- /dev/null +++ b/roles/stop_vms/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for stop_vms diff --git a/roles/stop_vms/handlers/main.yml b/roles/stop_vms/handlers/main.yml new file mode 100644 index 0000000..0bcb25f --- /dev/null +++ b/roles/stop_vms/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for stop_vms diff --git a/roles/stop_vms/meta/main.yml b/roles/stop_vms/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/stop_vms/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/stop_vms/tasks/main.yml b/roles/stop_vms/tasks/main.yml new file mode 100644 index 0000000..5e7a53d --- /dev/null +++ b/roles/stop_vms/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: Fetch VM status + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.vmid }}/status/current" + method : GET + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.vmid }}" + return_content : no + validate_certs : no + register : r_fetch_status + loop : "{{ lab_nodes }}" + loop_control : + label : "{{ item.name }}" + until : r_fetch_status.status == 200 and r_fetch_status.json.data.status is defined + retries : "{{ __api_retries }}" + delay : "{{ __api_polling }}" + + +- name: Stop VMs + uri: + url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/\ + {{ item.item.vmid }}/status/stop" + method : POST + headers : + Content-type : "application/x-www-form-urlencoded" + Authorization : "{{ __pve_token }}" + vmid : "{{ item.item.vmid }}" + return_content : no + validate_certs : no + register : r_stop_vm + loop : "{{ r_fetch_status.results }}" + loop_control : + label : "{{ item.json.data.name }}" + when : + - item.json.data.status == 'running'|lower + + +... diff --git a/roles/stop_vms/tests/inventory b/roles/stop_vms/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/stop_vms/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/stop_vms/tests/test.yml b/roles/stop_vms/tests/test.yml new file mode 100644 index 0000000..23b3f35 --- /dev/null +++ b/roles/stop_vms/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - stop_vms diff --git a/roles/stop_vms/vars/main.yml b/roles/stop_vms/vars/main.yml new file mode 100644 index 0000000..9e1797a --- /dev/null +++ b/roles/stop_vms/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for stop_vms