hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
72 stars 110 forks source link

packer fails with ansible provisioner #25

Open ghost opened 3 years ago

ghost commented 3 years ago

This issue was originally opened by @jf as hashicorp/packer#10690. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Overview of the Issue

Packing without the ansible provisioner passes (so there is nothing wrong with my packer setup), but with the ansible provisioner I get a error message about * Error running "ansible-playbook --version": exit status 1.

ansible-playbook is in the path, and running ansible-playbook --version on the command line returns with status 0 and not 1. If this were a PATH issue, I would expect status 127, so it doesn't look like it's a PATH issue. I also just confirmed this, by uninstalling ansible, which results in packer giving the following instead:

* Error running "ansible-playbook --version": exec: "ansible-playbook":
==> Wait completed after 302 microseconds
==> Builds finished but no artifacts were created.
executable file not found in $PATH

Reproduction Steps

Packer version

Packer v1.7.0

Simplified Packer Buildfile

It's really your standard packer file as far as I'm concerned. The issue here is that removing the ansible provisioner makes the build process work. If I include ansible, the build process fails.

Simplified version:

{
    "variables": {
        "var__aws_access_key":   "{{ env `AWS_ACCESS_KEY_ID` }}",
        "var__aws_secret_key":   "{{ env `AWS_SECRET_ACCESS_KEY` }}",
        "var__aws_secret_token": "{{ env `AWS_SECURITY_TOKEN` }}"
    },
    "builders": [{
        "type": "amazon-ebs",

        "access_key": "{{ user `var__aws_access_key` }}",
        "secret_key": "{{ user `var__aws_secret_key` }}",
        "token":      "{{ user `var__aws_secret_token` }}",

        "ssh_username": "aaa"
    }],
    "provisioners": [{
        "script": "update_upgrade.sh",
        "execute_command": "chmod +x {{ .Path }}; sudo {{ .Path }}",
        "type": "shell"
    },{
        "type": "ansible",
        "user": "aaa",
        "playbook_file": "provision.yml",

        "use_proxy": "false",

        "extra_arguments": ["-vvv"]
    }]
}

Operating system and Environment details

OS, Architecture, and any other information you can provide about the environment.

I am on macOS Big Sur, on the M1 chip

Ansible (2.10.6) is installed in a python venv, and available in the path

Log Fragments and crash.log files

...
2021/02/24 15:19:29 Waiting for RPC address for: /usr/local/bin/packer
2021/02/24 15:19:29 packer-provisioner-shell plugin: [INFO] Packer version: 1.7.0 [go1.15.8 darwin amd64]
2021/02/24 15:19:29 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/02/24 15:19:29 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jf/.packerconfig
2021/02/24 15:19:29 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /Users/jf/.packerconfig
2021/02/24 15:19:29 packer-provisioner-shell plugin: [INFO] Setting cache directory: /Users/jf/packer/packer_cache
2021/02/24 15:19:29 packer-provisioner-shell plugin: args: []string{"packer-provisioner-shell"}
2021/02/24 15:19:29 packer-provisioner-shell plugin: Plugin address: unix /var/folders/d3/xqf60mbn76b9y0tsxwf_st9r0000gn/T/packer-plugin974076808
2021/02/24 15:19:29 packer-provisioner-shell plugin: Waiting for connection...
2021/02/24 15:19:29 Received unix RPC address for /usr/local/bin/packer: addr is /var/folders/d3/xqf60mbn76b9y0tsxwf_st9r0000gn/T/packer-plugin974076808
2021/02/24 15:19:29 packer-provisioner-shell plugin: Serving a plugin connection...
2021/02/24 15:19:29 Preparing build: amazon-ebs
2021/02/24 15:19:29 packer-builder-amazon-ebs plugin: [INFO] (aws): No AWS timeout and polling overrides have been set. Packer will default to waiter-specific delays and timeouts. If you would like to customize the length of time between retries and max number of retries you may do so by setting the environment variables AWS_POLL_DELAY_SECONDS and AWS_MAX_ATTEMPTS or the configuration options aws_polling_delay_seconds and aws_polling_max_attempts to your desired values.

1 error(s) occurred:

* Error running "ansible-playbook --version": exit status 1

2021/02/24 15:19:29 Build debug mode: true
2021/02/24 15:19:29 Force build: false
2021/02/24 15:19:29 On error:
Error: Failed to prepare build: "amazon-ebs"

1 error(s) occurred:

2021/02/24 15:19:29 Waiting on builds to complete...
* Error running "ansible-playbook --version": exit status 1

Debug mode enabled. Builds will not be parallelized.

==> Wait completed after 265 microseconds
==> Wait completed after 265 microseconds

==> Builds finished but no artifacts were created.
==> Builds finished but no artifacts were created.
2021/02/24 15:19:29 [INFO] (telemetry) Finalizing.
2021/02/24 15:19:30 waiting for all plugin processes to complete...
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
2021/02/24 15:19:30 /usr/local/bin/packer: plugin process exited
(venv) j:packer jf@s027$
clayrisser commented 2 months ago

I'm also getting this error