tofu and molecule combined test, first try
Some checks failed
Gitea Actions - molecule test work / Explore-terraform-molecule-Gitea-Action (push) Failing after 1m15s

This commit is contained in:
Mike Holloway 2025-01-07 06:18:10 -05:00
parent 5cbd574a02
commit 189e33d9f4
2 changed files with 87 additions and 49 deletions

View File

@ -20,10 +20,10 @@ jobs:
- name: tofu output capture - name: tofu output capture
run: | run: |
export TARGET_IP_ADDRESS=$(tofu output -raw act_worker_ip_address) export TARGET_IP_ADDRESS=$(tofu output -raw act_worker_ip_address)
echo $TARGET_IP_ADDRESS cd ${{ gitea.workspace}}/podman-host/extensions
sleep 300 molecule test
working-directory: "${{ gitea.workspace }}/.gitea/tofu" working-directory: "${{ gitea.workspace }}/.gitea/tofu"
- name: tofu destroy - name: tofu destroy
run: "tofu destroy -auto-approve" run: "sleep 180 && tofu destroy -auto-approve"
working-directory: "${{ gitea.workspace }}/.gitea/tofu" working-directory: "${{ gitea.workspace }}/.gitea/tofu"

View File

@ -4,53 +4,91 @@
connection: local connection: local
gather_facts: false gather_facts: false
# no_log: "{{ molecule_no_log }}" # no_log: "{{ molecule_no_log }}"
tasks: vars:
# TODO: Developer must implement and populate 'server' variable molecule_inventory:
- name: Import state into tofu all:
command: hosts: {}
cmd: | linode: {}
{{ item }}
chdir: "/workspace/seasharp/ansible-role_podman-host/tofu"
loop:
- tofu init
- tofu import module.main_vpc_subnet.linode_vpc.eqit_vpc {{ lookup('env', 'EQIT_VPC') }}
- tofu import module.main_vpc_subnet.linode_vpc_subnet.eqit_vpc_subnet "{{ lookup('env', 'EQIT_VPC') }}, {{ lookup('env', 'EQIT_VPC_SUBNET') }}"
- tofu refresh
- name: Tofu show tasks:
- name: Confirm we can reach
command: command:
cmd: | cmd: "ping -c5 {{ lookup('env', 'TARGET_IP_ADDRESS') }}"
tofu state ls register: isping
chdir: "/workspace/seasharp/ansible-role_podman-host/tofu"
register: mycmd
## grep names from subnet data
## tofu import module.instance
- debug: - debug:
msg: | msg: |
{{ mycmd.stdout_lines }} "{{ isping.failed }}"
# - name: Create instance config
# when: server.changed | default(false) | bool # noqa no-handler - name: Fail if instance is not running
# block: when: isping.failed
# - name: Populate instance config dict # noqa jinja fail:
# ansible.builtin.set_fact:
# instance_conf_dict: {} - name: Add linode to molecule_inventory
# # instance': "{{ }}", vars:
# # address': "{{ }}", inventory_partial_yaml: |
# # user': "{{ }}", all:
# # port': "{{ }}", children:
# # 'identity_file': "{{ }}", } linode:
# with_items: "{{ server.results }}" hosts:
# register: instance_config_dict "{{ lookup('env', 'TARGET_IP_ADDRESS') }}":
# ansible_ssh_private_key_file: "{{ lookup('env', 'GITHUB_WORKSPACE') }}/.ssh/act_runner_id-ed25519"
# - name: Convert instance config dict to a list ansible_connection: ssh
# ansible.builtin.set_fact: service_users:
# instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" - name: serviceuser1
# services:
# - name: Dump instance config - service1
# ansible.builtin.copy: - service2
# content: | ansible.builtin.set_fact:
# # Molecule managed molecule_inventory: >
# {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }}
# {{ instance_conf | to_json | from_json | to_yaml }}
# dest: "{{ molecule_instance_config }}" - name: Dump molecule_inventory
# mode: "0600" ansible.builtin.copy:
content: |
{{ molecule_inventory | to_yaml }}
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
mode: "0600"
- name: Force inventory refresh
ansible.builtin.meta: refresh_inventory
- name: Fail if linode group is missing
ansible.builtin.assert:
that: "'linode' in groups"
fail_msg: |
linode group was not found inside inventory groups: {{ groups }}
run_once: true # noqa: run-once[task]
# we want to avoid errors like "Failed to create temporary directory"
- name: Validate that inventory was refreshed
hosts: linode
gather_facts: false
tasks:
- name: Check uname
ansible.builtin.raw: uname -a
register: result
changed_when: false
- name: Display uname info
ansible.builtin.debug:
msg: "{{ result.stdout }}"
- name: Verify linode properties
hosts: linode
gather_facts: false
tasks:
- name: Packages openssh-server, python3-policycoreutils
ansible.builtin.dnf:
name: ['openssh-server', 'python3-policycoreutils']
state: present
- name: systemd PID
command: ps -q 1
register: ps_result
changed_when: false
- name: Display PID 1 info
ansible.builtin.debug:
msg: "{{ ps_result.stdout }}"