diff --git a/README.md b/README.md index 4178fab..13ef57b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,12 @@ provisioning test resources. Please note that this driver is currently in its early stage of development. +This plugin requires google.cloud and community.crypto collections to be present: +``` +ansible-galaxy collection install google.cloud +ansible-galaxy collection install community.crypto +``` + # Installation and Usage Install molecule-gce : diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index d1da848..754c40e 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -5,6 +5,6 @@ gather_facts: true tasks: - name: Display info - debug: + ansible.builtin.debug: msg: > {{ ansible_distribution }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }} diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 7972c13..076f259 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -4,4 +4,4 @@ gather_facts: false tasks: - name: Wait 600 seconds for target connection to become reachable/usable - wait_for_connection: + ansible.builtin.wait_for_connection: diff --git a/src/molecule_gce/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/converge.yml b/src/molecule_gce/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/converge.yml index fecf1c8..cc63d86 100644 --- a/src/molecule_gce/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/converge.yml +++ b/src/molecule_gce/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/converge.yml @@ -3,5 +3,5 @@ hosts: all tasks: - name: "Include {{ cookiecutter.role_name }}" - include_role: + ansible.builtin.include_role: name: "{{ cookiecutter.role_name }}" diff --git a/src/molecule_gce/driver.py b/src/molecule_gce/driver.py index 7e61266..2137b09 100644 --- a/src/molecule_gce/driver.py +++ b/src/molecule_gce/driver.py @@ -173,4 +173,4 @@ def template_dir(self): @property def required_collections(self) -> Dict[str, str]: # https://galaxy.ansible.com/google/cloud - return {"google.cloud": "1.0.2"} + return {"google.cloud": "1.0.2", "community.crypto": "1.8.0"} diff --git a/src/molecule_gce/playbooks/create.yml b/src/molecule_gce/playbooks/create.yml index 0a3e6b0..ed04135 100644 --- a/src/molecule_gce/playbooks/create.yml +++ b/src/molecule_gce/playbooks/create.yml @@ -10,22 +10,22 @@ tasks: - name: Make sure if linux or windows either specified - assert: + ansible.builtin.assert: that: - molecule_yml.driver.instance_os_type | lower == "linux" or molecule_yml.driver.instance_os_type | lower == "windows" fail_msg: "instance_os_type is possible only to specify linux or windows either" - name: Include create_linux_instance tasks - include_tasks: tasks/create_linux_instance.yml + ansible.builtin.include_tasks: tasks/create_linux_instance.yml when: - molecule_yml.driver.instance_os_type | lower == "linux" - name: Include create_windows_instance tasks - include_tasks: tasks/create_windows_instance.yml + ansible.builtin.include_tasks: tasks/create_windows_instance.yml when: - molecule_yml.driver.instance_os_type | lower == "windows" handlers: - name: Import main handler tasks - import_tasks: handlers/main.yml + ansible.builtin.import_tasks: handlers/main.yml diff --git a/src/molecule_gce/playbooks/destroy.yml b/src/molecule_gce/playbooks/destroy.yml index deb86bb..1357a6c 100644 --- a/src/molecule_gce/playbooks/destroy.yml +++ b/src/molecule_gce/playbooks/destroy.yml @@ -25,7 +25,7 @@ - "Dump instance config" - name: Wait for instance(s) deletion to complete - async_status: + ansible.builtin.async_status: jid: "{{ item.ansible_job_id }}" register: server until: server.finished @@ -35,4 +35,4 @@ handlers: - name: Import main handler tasks - import_tasks: handlers/main.yml + ansible.builtin.import_tasks: handlers/main.yml diff --git a/src/molecule_gce/playbooks/handlers/main.yml b/src/molecule_gce/playbooks/handlers/main.yml index 1259137..c1cb55d 100644 --- a/src/molecule_gce/playbooks/handlers/main.yml +++ b/src/molecule_gce/playbooks/handlers/main.yml @@ -1,6 +1,6 @@ --- - name: Populate instance config dict Linux - set_fact: + ansible.builtin.set_fact: instance_conf_dict: { 'instance': "{{ instance_info.name }}", 'address': "{{ instance_info.networkInterfaces.0.accessConfigs.0.natIP if molecule_yml.driver.external_access else instance_info.networkInterfaces.0.networkIP }}", @@ -16,7 +16,7 @@ register: instance_conf_dict - name: Populate instance config dict Windows - set_fact: + ansible.builtin.set_fact: instance_conf_dict: { 'instance': "{{ instance_info.name }}", 'address': "{{ instance_info.networkInterfaces.0.accessConfigs.0.natIP if molecule_yml.driver.external_access else instance_info.networkInterfaces.0.networkIP }}", @@ -35,15 +35,15 @@ - name: Wipe out instance config - set_fact: + ansible.builtin.set_fact: instance_conf: {} - name: Convert instance config dict to a list - set_fact: + ansible.builtin.set_fact: instance_conf: "{{ instance_conf_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" - name: Dump instance config - copy: + ansible.builtin.copy: content: "{{ instance_conf }}" dest: "{{ molecule_instance_config }}" mode: '0600' diff --git a/src/molecule_gce/playbooks/tasks/create_linux_instance.yml b/src/molecule_gce/playbooks/tasks/create_linux_instance.yml index 2782b90..f6ae0f2 100644 --- a/src/molecule_gce/playbooks/tasks/create_linux_instance.yml +++ b/src/molecule_gce/playbooks/tasks/create_linux_instance.yml @@ -1,6 +1,6 @@ --- - name: create ssh keypair - openssh_keypair: + community.crypto.openssh_keypair: comment: "{{ lookup('env','USER') }} user for Molecule" path: "{{ ssh_identity_file }}" register: keypair @@ -42,7 +42,7 @@ poll: 0 - name: Wait for instance(s) creation to complete - async_status: + ansible.builtin.async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ async_results.results }}" register: server @@ -55,7 +55,7 @@ - "Dump instance config" - name: Wait for SSH - wait_for: + ansible.builtin.wait_for: port: 22 host: "{{ item.networkInterfaces.0.accessConfigs.0.natIP if molecule_yml.driver.external_access else item.networkInterfaces.0.networkIP }}" search_regex: SSH diff --git a/src/molecule_gce/playbooks/tasks/create_windows_instance.yml b/src/molecule_gce/playbooks/tasks/create_windows_instance.yml index 1dc1c76..c3193f4 100644 --- a/src/molecule_gce/playbooks/tasks/create_windows_instance.yml +++ b/src/molecule_gce/playbooks/tasks/create_windows_instance.yml @@ -32,7 +32,7 @@ poll: 0 - name: Wait for instance(s) creation to complete - async_status: + ansible.builtin.async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ async_results.results }}" register: server @@ -45,14 +45,14 @@ - "Dump instance config" - name: Wait for WinRM - wait_for: + ansible.builtin.wait_for: port: 5986 host: "{{ item.networkInterfaces.0.accessConfigs.0.natIP if molecule_yml.driver.external_access else item.networkInterfaces.0.networkIP }}" delay: 10 loop: "{{ server.results }}" - name: Prepare Windows User - script: ./files/windows_auth.py --instance {{ item.name }} --zone {{ item.zone | default(molecule_yml.driver.region + '-b') }} --project {{ gcp_project_id }} --username molecule_usr + ansible.builtin.script: ./files/windows_auth.py --instance {{ item.name }} --zone {{ item.zone | default(molecule_yml.driver.region + '-b') }} --project {{ gcp_project_id }} --username molecule_usr args: executable: python3 environment: @@ -66,7 +66,7 @@ delay: 10 - name: Add password for instances in server list - set_fact: + ansible.builtin.set_fact: win_instances: "{{ win_instances|default([]) + [dict(item[0], password=item[1].stdout_lines |last)] }}" loop: "{{ server.results | zip(password.results) | list }}" no_log: true