Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ec2 template for molecule #2230

Closed
wants to merge 1 commit into from
Closed

Conversation

delgod
Copy link

@delgod delgod commented Aug 17, 2019

  • support multiple Regions
  • support multiple VPCs in one Region
  • support CentOS and Debian images
  • correctly populate instance name via Tags

Please include details of what it is, how to use it, how it's been tested
Please include an entry in the CHANGELOG.md if the change will impact users.

changes are backward compatible and shouldn't affect current users

How to test

platforms:
  - name: centos-7
    region: eu-central-1
    image: ami-0837950ffca9ae6e8
    vpc_subnet_id: subnet-xxxxxx
    instance_type: t3.micro
    ssh_user: centos
    instance_tags:
      iit-billing-tag: molecule-worker
  - name: rhel-8
    region: us-east-1
    image: ami-098bb5d92c8886ca1
    vpc_subnet_id: subnet-xxxxxx
    instance_type: t2.micro
    ssh_user: ec2-user
    instance_tags:
      iit-billing-tag: jenkins-pg-worker

PR Type

  • Bugfix Pull Request

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try to point problems I identified so far so you can address them quickly
a) title + description is misleading users because apparently you are improving only the ec2 template without altering the driver itself. that is good because it avoids breaking current users but needs to be clarifier
b) our travis tests are not doing any ec2 testing, so it will very unlikely to get positive feedback

We need to find an way to enable me (or someone else) to test the ec2 at least locally if not on CI. I happen to have personal aws account which I could use to test it (hopefully it will not leave any leftovers after running).

If you can give me some hints on how to test it I will be happy to help you.

@delgod delgod changed the title improve ec2 driver improve ec2 template for molecule Aug 20, 2019
@delgod
Copy link
Author

delgod commented Aug 20, 2019

Hi Sorin!

I have improved title a bit ;)
please find the article - https://blog.codecentric.de/en/2019/01/ansible-molecule-travisci-aws/
it is a very good starting point, changes are backward compatible, so article must work fine.

@ssbarnea
Copy link
Member

While trying it myself I ended up encountering ansible/ansible#60949

* support multiple Regions
* support multiple VPCs in one Region
* support CentOS and Debian images
* correctly populate instance name via Tags

Signed-off-by: Mykola Marzhan <[email protected]>
Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failed to pass even the most basic use case: molecule init role -d ec2 -r foo and running create on it.

    TASK [Check subnet] ************************************************************
    Saturday 12 October 2019  09:44:06 +0100 (0:00:00.270)       0:00:00.270 ******
    ok: [localhost] => (item={'name': 'instance', 'image': 'ami-a5b196c0', 'instance_type': 't2.micro', 'vpc_subnet_id': 'subnet-6456fd1f'})

    TASK [debug] *******************************************************************
    Saturday 12 October 2019  09:44:07 +0100 (0:00:00.914)       0:00:01.184 ******
    ok: [localhost] => {
        "subnet_facts": {
            "changed": false,
            "msg": "All items completed",
            "results": [
                {
                    "ansible_loop_var": "item",
                    "changed": false,
                    "failed": false,
                    "invocation": {
                        "module_args": {
                            "aws_access_key": null,
                            "aws_secret_key": null,
                            "debug_botocore_endpoint_logs": false,
                            "ec2_url": null,
                            "filters": {
                                "subnet-id": "subnet-6456fd1f"
                            },
                            "profile": null,
                            "region": "eu-west-2",
                            "security_token": null,
                            "subnet_ids": [],
                            "validate_certs": true
                        }
                    },
                    "item": {
                        "image": "ami-a5b196c0",
                        "instance_type": "t2.micro",
                        "name": "instance",
                        "vpc_subnet_id": "subnet-6456fd1f"
                    },
                    "subnets": []
                }
            ]
        }
    }

    TASK [Populate subnet vpc] *****************************************************
    Saturday 12 October 2019  09:44:07 +0100 (0:00:00.039)       0:00:01.224 ******
    fatal: [localhost]: FAILED! => {}

    MSG:

    The task includes an option with an undefined variable. The error was: list object has no element 0

    The error appears to be in '/Users/ssbarnea/os/molecule/foo-ec2/molecule/default/create.yml': line 42, column 7, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


        - name: Populate subnet vpc
          ^ here

@ssbarnea
Copy link
Member

I am going to close this PR as is clearly breaking the driver. Feel free to raise it again once this sequence does not fail to pass:

molecule init role -d ec2 -r test-ec2
cd test-ec2
molecule create
molecule init
molecule destroy

@ssbarnea ssbarnea closed this Oct 12, 2019
@delgod
Copy link
Author

delgod commented Oct 15, 2019

Hi @ssbarnea,

I have double-checked - everything works fine :(
looks like you have configured the wrong subnet-id in molecule/default/molecule.yml
keep in mind each AWS user has its own subnets.

Could you please try again?

@retpolanne
Copy link
Contributor

@ssbarnea I've been using @delgod fork for some time and that error happens because molecule just adds a random subnet ID to the molecule.yml file. Changing it to a subnet ID on your account works fine.

@delgod thanks for the PR anyways, it helped me as heck :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants