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

How to make ansible-provisioner not error out if a role is already installed #185

Closed
nandac opened this issue Apr 13, 2024 · 1 comment
Closed
Labels

Comments

@nandac
Copy link

nandac commented Apr 13, 2024

Dear Folks,

I am using the Ansible Packer provisioner to execute a playbook on one or more AWS instances brought up by Packer to build a custom Amazon Managed Image (AMI).

The instances are brought up in parallel but the issue is when I execute the Ansible provisioner it errors out in cases where it tries to reinstall roles that are already installed and asks me to use --ignore-errors.

amazon-ebs.build_ami: [WARNING]: - ansible_role_<REDACTED> was NOT installed successfully: the
amazon-ebs.build_ami: Starting galaxy role install process
amazon-ebs.build_ami: specified role ansible_role_<REDACTED> appears to already exist. Use
amazon-ebs.build_ami: --force to replace it.
amazon-ebs.build_ami: - extracting ansible_role_<REDACTED> to <REDACTED>/.ansible/roles/ansible_role_<REDACTED>
amazon-ebs.build_ami: ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
==> amazon-ebs.build_ami: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs.build_ami: Terminating the source AWS instance...

Is there any way to stop the provisioner from trying to install the roles multiple times or send in --ignore-errors to the Ansible galaxy command used by the provisioner?

I have tried setting this up using the galaxy_command option but could not figure it out.

I also tried setting a custom roles-path and collections-path but the provisioner still installed the roles and collections to the default location specified by Ansible.

I would like to keep building the AMIs in parallel.

Here is my redacted build config:

build {
  dynamic "source" {
    for_each = local.images
    labels   = ["amazon-ebs.ami"]

    content {
      name       = "build_${source.value.value_one}_${source.value.value_two}_${source.value_three}"
      value_one   = source.value.value_one
      value_two = source.value.value_two
      value_three   = source.value.value_three
    }
 }

And here is my redacted ansible provisioner config:

provisioner "ansible" {
    playbook_file  = "playbook.yml"
    galaxy_file    = "requirements.yml"
    use_proxy      = false

    ansible_env_vars = [
      "ANSIBLE_FORCE_COLOR=1",                 # Force colored output
      "ANSIBLE_PYTHON_INTERPRETER=auto_silent" # Silence warning about Python discovery
    ]

    extra_arguments = [
      "--extra-vars", "\"ansible_python_interpreter=/usr/bin/env python3\"", # Find Python 3 on PATH
    ]
  }

I hope someone could give me a way to either use --ignore-errors which is not ideal or some other way to get around this issue.

@lbajolet-hashicorp
Copy link
Contributor

Hi @nandac,

Sorry I took some time to respond to this issue, but since you're asking a general usage question I would encourage you to migrate this over to Discuss, as this is where our community is most active, and will more likely be able to help you on this.

Github issues in general are reserved for anything that needs maintainer attention: signalling bugs, requesting features, etc.

I'll close this issue for now, but please feel free to reopen if I missed something, thanks!

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

No branches or pull requests

2 participants