Skip to content

Commit

Permalink
enhancement: add fqcn to cookicutter files of ec2, containers and doc…
Browse files Browse the repository at this point in the history
…ker (#168)

* enhancement: add fqcn to cookicutter files of ec2, containers and docker

* remove corresponding fqcn lines in .ansible-lint-ignore, fix requirements.yml for using amazon.aws and changed in README
  • Loading branch information
bernd-mueller-el authored Jun 28, 2023
1 parent 3676f28 commit 73bc48a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 63 deletions.
28 changes: 0 additions & 28 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,15 @@ src/molecule_plugins/gce/playbooks/tasks/create_windows_instance.yml yaml[line-l

src/molecule_plugins/podman/playbooks/create.yml yaml[line-length]

test/azure/scenarios/driver/azure/molecule/multi-node/prepare.yml fqcn[action-core]

test/gce/scenarios/linux/converge.yml fqcn[action-core]
test/gce/scenarios/linux/create.yml fqcn[action-core]
test/gce/scenarios/linux/destroy.yml fqcn[action-core]
test/gce/scenarios/linux/handlers/main.yml fqcn[action-core]
test/gce/scenarios/linux/handlers/main.yml yaml[line-length]
test/gce/scenarios/linux/molecule.yml yaml[line-length]
test/gce/scenarios/linux/prepare.yml fqcn[action-core]
test/gce/scenarios/linux/tasks/create_linux_instance.yml fqcn[action-core]
test/gce/scenarios/linux/tasks/create_linux_instance.yml yaml[line-length]
test/gce/scenarios/linux/tasks/create_windows_instance.yml fqcn[action-core]
test/gce/scenarios/linux/tasks/create_windows_instance.yml yaml[line-length]
test/gce/scenarios/linux/verify.yml fqcn[action-core]

test/gce/scenarios/windows/converge.yml fqcn[action-core]
test/gce/scenarios/windows/create.yml fqcn[action-core]
test/gce/scenarios/windows/destroy.yml fqcn[action-core]
test/gce/scenarios/windows/handlers/main.yml fqcn[action-core]
test/gce/scenarios/windows/handlers/main.yml yaml[line-length]
test/gce/scenarios/windows/molecule.yml yaml[line-length]
test/gce/scenarios/windows/prepare.yml fqcn[action-core]
test/gce/scenarios/windows/tasks/create_linux_instance.yml fqcn[action-core]
test/gce/scenarios/windows/tasks/create_linux_instance.yml yaml[line-length]
test/gce/scenarios/windows/tasks/create_windows_instance.yml fqcn[action-core]
test/gce/scenarios/windows/tasks/create_windows_instance.yml yaml[line-length]
test/gce/scenarios/windows/verify.yml fqcn[action-core]

test/roles/azureplugin/meta/main.yml meta-incorrect
test/roles/azureplugin/meta/main.yml meta-no-info
Expand All @@ -46,26 +28,17 @@ test/roles/azureplugin/tests/test.yml name[play]
test/roles/dockerplugin/meta/main.yml meta-incorrect
test/roles/dockerplugin/meta/main.yml meta-no-info
test/roles/dockerplugin/meta/main.yml schema[meta]
test/roles/dockerplugin/molecule/default/converge.yml fqcn[action-core]
test/roles/dockerplugin/molecule/default/verify.yml yaml[indentation]
test/roles/dockerplugin/tests/test.yml name[play]

test/roles/ec2plugin/meta/main.yml meta-incorrect
test/roles/ec2plugin/meta/main.yml meta-no-info
test/roles/ec2plugin/meta/main.yml schema[meta]
test/roles/ec2plugin/molecule/default/converge.yml fqcn[action-core]
test/roles/ec2plugin/molecule/default/create.yml fqcn[action-core]
test/roles/ec2plugin/molecule/default/create.yml fqcn[action]
test/roles/ec2plugin/molecule/default/create.yml fqcn[keyword]
test/roles/ec2plugin/molecule/default/create.yml key-order[task]
test/roles/ec2plugin/molecule/default/create.yml name[missing]
test/roles/ec2plugin/molecule/default/create.yml no-handler
test/roles/ec2plugin/molecule/default/create.yml risky-file-permissions
test/roles/ec2plugin/molecule/default/destroy.yml fqcn[action-core]
test/roles/ec2plugin/molecule/default/destroy.yml fqcn[action]
test/roles/ec2plugin/molecule/default/destroy.yml fqcn[keyword]
test/roles/ec2plugin/molecule/default/destroy.yml risky-file-permissions
test/roles/ec2plugin/molecule/default/prepare.yml fqcn[action-core]
test/roles/ec2plugin/molecule/default/verify.yml yaml[indentation]
test/roles/ec2plugin/tests/test.yml name[play]

Expand All @@ -92,4 +65,3 @@ test/roles/containersplugin/meta/main.yml meta-no-info
test/roles/containersplugin/meta/main.yml schema[meta]
test/roles/containersplugin/molecule/default/verify.yml yaml[indentation]
test/roles/containersplugin/tests/test.yml name[play]
test/roles/containersplugin/molecule/default/converge.yml fqcn[action-core]
2 changes: 1 addition & 1 deletion doc/ec2/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ With a new role
This will create a new folder *my-role* containing a bare-bone generated
role like you would do with ``ansible-galaxy init`` command.
It will also contain a molecule folder with a default scenario
using the ec2 driver (using ansible community.aws.ec2_instance collection).
using the ec2 driver (using ansible amazon.aws.ec2_instance collection).
Install the collection using
`ansible-galaxy install -r test_requirements.yml`.

Expand Down
2 changes: 1 addition & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ collections:
- name: ansible.posix # docker
version: ">=1.4.0"
- name: google.cloud
- name: community.aws
- name: amazon.aws
- name: community.docker
version: ">=3.0.2"
- name: containers.podman
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
gather_facts: false
tasks:
- name: Test implementation
debug:
ansible.builtin.debug:
msg: Add test implementation here
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
hosts: all
tasks:
- name: "Include {{ cookiecutter.role_name }}"
include_role:
ansible.builtin.include_role:
name: "{{ cookiecutter.role_name }}"
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
hosts: all
tasks:
- name: "Include {{ cookiecutter.role_name }}"
include_role:
ansible.builtin.include_role:
name: "{{ cookiecutter.role_name }}"
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
collections:
- community.aws
- community.crypto
vars:
# Run config handling
default_run_id: "{{ lookup('password', '/dev/null chars=ascii_lowercase length=5') }}"
Expand Down Expand Up @@ -85,7 +82,7 @@
| list }}
pre_tasks:
- name: Validate platform configurations
assert:
ansible.builtin.assert:
that:
- platforms | length > 0
- platform.name is string and platform.name | length > 0
Expand Down Expand Up @@ -120,12 +117,12 @@
label: "{{ platform.name }}"
tasks:
- name: Write run config to file
copy:
ansible.builtin.copy:
dest: "{{ run_config_path }}"
content: "{{ run_config | to_yaml }}"

- name: Generate local key pairs
openssh_keypair:
community.crypto.openssh_keypair:
path: "{{ item.private_key_path }}"
type: rsa
size: 2048
Expand All @@ -136,7 +133,7 @@
register: local_keypairs

- name: Look up EC2 AMI(s) by owner and name (if image not set)
ec2_ami_info:
amazon.aws.ec2_ami_info:
owners: "{{ item.image_owner }}"
filters: "{{ item.image_filters | default({}) | combine(image_name_map) }}"
vars:
Expand All @@ -148,7 +145,7 @@
register: ami_info

- name: Look up subnets to determine VPCs (if needed)
ec2_vpc_subnet_info:
amazon.aws.ec2_vpc_subnet_info:
subnet_ids: "{{ item.vpc_subnet_id }}"
loop: "{{ platforms }}"
loop_control:
Expand All @@ -157,7 +154,7 @@
register: subnet_info

- name: Validate discovered information
assert:
ansible.builtin.assert:
that:
- platform.image or (ami_info.results[index].images | length > 0)
- platform.vpc_id or (subnet_info.results[index].subnets | length > 0)
Expand All @@ -169,7 +166,7 @@
label: "{{ platform.name }}"

- name: Create ephemeral EC2 keys (if needed)
ec2_key:
amazon.aws.ec2_key:
profile: "{{ item.aws_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
name: "{{ item.key_name }}"
Expand All @@ -184,7 +181,7 @@
register: ec2_keys

- name: Create ephemeral security groups (if needed)
ec2_group:
amazon.aws.ec2_security_group:
profile: "{{ item.aws_profile | default(omit) }}"
iam_instance_profile: "{{ item.iam_instance_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
Expand All @@ -202,7 +199,7 @@
when: item.security_groups | length == 0

- name: Create ephemeral EC2 instance(s)
ec2_instance:
amazon.aws.ec2_instance:
profile: "{{ item.aws_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
filters: "{{ platform_filters }}"
Expand Down Expand Up @@ -250,9 +247,10 @@
async: 7200
poll: 0

- block:
- name: Instance boot block
block:
- name: Wait for instance creation to complete
async_status:
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
loop: "{{ ec2_instances_async.results }}"
loop_control:
Expand All @@ -263,7 +261,7 @@
retries: 300

- name: Collect instance configs
set_fact:
ansible.builtin.set_fact:
instance_config:
instance: "{{ item.name }}"
address: "{{ item.assign_public_ip | ternary(instance.public_ip_address, instance.private_ip_address) }}"
Expand All @@ -281,7 +279,7 @@
register: instance_configs

- name: Write Molecule instance configs
copy:
ansible.builtin.copy:
dest: "{{ molecule_instance_config }}"
content: >-
{{ instance_configs.results
Expand All @@ -292,7 +290,7 @@
| to_yaml }}
- name: Start SSH pollers
wait_for:
ansible.builtin.wait_for:
host: "{{ item.address }}"
port: "{{ item.port }}"
search_regex: SSH
Expand All @@ -306,7 +304,7 @@
poll: 0

- name: Wait for SSH
async_status:
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
loop: "{{ ssh_wait_async.results }}"
loop_control:
Expand All @@ -318,7 +316,7 @@
delay: 1

- name: Wait for boot process to finish
pause:
ansible.builtin.pause:
seconds: "{{ platforms | map(attribute='boot_wait_seconds') | max }}"
when: ec2_instances_async is changed
{%- endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
collections:
- community.aws
vars:
# Run config handling
default_run_id: "{{ lookup('password', '/dev/null chars=ascii_lowercase length=5') }}"
Expand Down Expand Up @@ -46,7 +44,7 @@
instance_config: "{{ (lookup('file', molecule_instance_config, errors='ignore') or '{}') | from_yaml }}"
pre_tasks:
- name: Validate platform configurations
assert:
ansible.builtin.assert:
that:
- platforms | length > 0
- platform.name is string and platform.name | length > 0
Expand All @@ -65,7 +63,7 @@
label: "{{ platform.name }}"
tasks:
- name: Look up subnets to determine VPCs (if needed)
ec2_vpc_subnet_info:
amazon.aws.ec2_vpc_subnet_info:
subnet_ids: "{{ item.vpc_subnet_id }}"
loop: "{{ platforms }}"
loop_control:
Expand All @@ -74,7 +72,7 @@
register: subnet_info

- name: Validate discovered information
assert:
ansible.builtin.assert:
that: platform.vpc_id or (subnet_info.results[index].subnets | length > 0)
quiet: true
loop: "{{ platforms }}"
Expand All @@ -84,7 +82,7 @@
label: "{{ platform.name }}"

- name: Destroy ephemeral EC2 instances
ec2_instance:
amazon.aws.ec2_instance:
profile: "{{ item.aws_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
instance_ids: "{{ instance_config | map(attribute='instance_ids') | flatten }}"
Expand All @@ -97,7 +95,7 @@
poll: 0

- name: Wait for instance destruction to complete
async_status:
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
loop: "{{ ec2_instances_async.results }}"
loop_control:
Expand All @@ -108,12 +106,12 @@
retries: 300

- name: Write Molecule instance configs
copy:
ansible.builtin.copy:
dest: "{{ molecule_instance_config }}"
content: "{{ {} | to_yaml }}"

- name: Destroy ephemeral security groups (if needed)
ec2_group:
amazon.aws.ec2_security_group:
profile: "{{ item.aws_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
vpc_id: "{{ item.vpc_id or vpc_subnet.vpc_id }}"
Expand All @@ -128,7 +126,7 @@
when: item.security_groups | length == 0

- name: Destroy ephemeral keys (if needed)
ec2_key:
amazon.aws.ec2_key:
profile: "{{ item.aws_profile | default(omit) }}"
region: "{{ item.region | default(omit) }}"
name: "{{ item.key_name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
gather_facts: false
tasks:
- name: Make sure python3 is installed
package:
ansible.builtin.package:
name: python3
state: present
become: true
Expand Down

0 comments on commit 73bc48a

Please sign in to comment.