Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
fix an issue that errors have been occurring by ansible lint 5 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-joker authored Jun 19, 2021
1 parent c61095b commit 1a9461c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
molecule_yml.driver.instance_os_type == "windows"
fail_msg: "instance_os_type is possible only to specify linux or windows either"

- include_tasks: create_linux_instance.yml
- name: Include create_linux_instance tasks
include_tasks: tasks/create_linux_instance.yml
when:
- molecule_yml.driver.instance_os_type == "linux"

- include_tasks: create_windows_instance.yml
- name: Include create_windows_instance tasks
include_tasks: tasks/create_windows_instance.yml
when:
- molecule_yml.driver.instance_os_type == "windows"

handlers:
- name: Import main handler tasks
import_tasks: handlers/main.yml
{%- endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
name: "{{ item.name }}"
force: true
state: absent
no_log: true
async: 7200
poll: 0
register: async_results
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
{% raw -%}
- name: Populate instance config dict for linux
set_fact:
instance_conf_dict: {
'instance': "{{ instance_info.item.item.name }}",
'address': "{{ instance_info.instance.ipv4 }}",
'user': "{{ molecule_yml.driver.vm_username }}",
'port': 22,
'identity_file': "{{ keypair_path }}",
'instance_os_type': "{{ molecule_yml.driver.instance_os_type }}"
}
loop: "{{ server.results }}"
loop_control:
loop_var: instance_info
register: instance_config_dict

- name: Populate instance config dict for windows
set_fact:
instance_conf_dict: {
'instance': "{{ instance_info.item.item.name }}",
'address': "{{ instance_info.instance.ipv4 }}",
'port': "{{ molecule_yml.driver.winrm_port | default(5986) }}",
'connection': "{{ molecule_yml.driver.connection | default('winrm') }}",
'user': "{{ molecule_yml.driver.vm_username }}",
'password': "{{ molecule_yml.driver.vm_password }}",
'winrm_transport': "{{ molecule_yml.driver.winrm_transport | default('ntlm') }}",
'winrm_server_cert_validation': "{{ molecule_yml.driver.winrm_server_cert_validation | default('ignore') }}",
'instance_os_type': "{{ molecule_yml.driver.instance_os_type }}"
}
loop: "{{ server.results }}"
loop_control:
loop_var: instance_info
register: instance_config_dict

- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
mode: 0644
{%- endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
wait_for_ip_address: true
wait_for_customization: true
state: poweredon
no_log: true
async: 7200
poll: 0
register: async_results
Expand All @@ -43,6 +44,10 @@
until: server.finished
delay: 10
retries: 300
notify:
- "Populate instance config dict for linux"
- "Convert instance config dict to a list"
- "Dump instance config"

- name: Check vmware tools status
vmware_guest_info:
Expand All @@ -53,6 +58,7 @@
datacenter: "{{ molecule_yml.driver.datacenter }}"
folder: "{{ molecule_yml.driver.folder }}"
name: "{{ item.name }}"
no_log: true
register: guest_state
until: "guest_state.instance.guest_tools_status == 'guestToolsRunning'"
delay: 10
Expand All @@ -74,33 +80,6 @@
vm_shell: /bin/bash
vm_shell_args: "-c 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo {{ keypair_result.ssh_public_key }} > ~/.ssh/authorized_keys'"
wait_for_process: true
no_log: true
loop: "{{ molecule_yml.platforms }}"

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ instance_info.item.item.name }}",
'address': "{{ instance_info.instance.ipv4 }}",
'user': "{{ molecule_yml.driver.vm_username }}",
'port': 22,
'identity_file': "{{ keypair_path }}",
'instance_os_type': "{{ molecule_yml.driver.instance_os_type }}"
}
loop: "{{ server.results }}"
loop_control:
loop_var: instance_info
register: instance_config_dict
when: server is changed

- name: Convert instance config dict to a list.
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server is changed

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
mode: 0644
when: server is changed
{%- endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
wait_for_ip_address: true
wait_for_customization: true
state: poweredon
no_log: true
async: 7200
poll: 0
register: async_results
Expand All @@ -40,6 +41,10 @@
until: server.finished
delay: 10
retries: 300
notify:
- "Populate instance config dict for windows"
- "Convert instance config dict to a list"
- "Dump instance config"

- name: Check vmware tools status
vmware_guest_info:
Expand All @@ -50,6 +55,7 @@
datacenter: "{{ molecule_yml.driver.datacenter }}"
folder: "{{ molecule_yml.driver.folder }}"
name: "{{ item.name }}"
no_log: true
register: guest_state
until: "guest_state.instance.guest_tools_status == 'guestToolsRunning'"
delay: 10
Expand Down Expand Up @@ -94,6 +100,7 @@
New-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset -ValueSet $valueset
}"
wait_for_process: true
no_log: true
loop: "{{ molecule_yml.platforms }}"

- name: Disable Windows Firewall
Expand All @@ -109,36 +116,6 @@
vm_shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
vm_shell_args: "-Command Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False"
wait_for_process: true
no_log: true
loop: "{{ molecule_yml.platforms }}"

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ instance_info.item.item.name }}",
'address': "{{ instance_info.instance.ipv4 }}",
'port': "{{ molecule_yml.driver.winrm_port | default(5986) }}",
'connection': "{{ molecule_yml.driver.connection | default('winrm') }}",
'user': "{{ molecule_yml.driver.vm_username }}",
'password': "{{ molecule_yml.driver.vm_password }}",
'winrm_transport': "{{ molecule_yml.driver.winrm_transport | default('ntlm') }}",
'winrm_server_cert_validation': "{{ molecule_yml.driver.winrm_server_cert_validation | default('ignore') }}",
'instance_os_type': "{{ molecule_yml.driver.instance_os_type }}"
}
loop: "{{ server.results }}"
loop_control:
loop_var: instance_info
register: instance_config_dict
when: server is changed

- name: Convert instance config dict to a list.
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server is changed

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
mode: 0644
when: server is changed
{%- endraw %}

0 comments on commit 1a9461c

Please sign in to comment.