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

Ansible incorrectly attempts connection to localhost (127.0.0.1) instead of host from packer inventory #179

Closed
akusei opened this issue Jan 10, 2024 · 2 comments
Labels

Comments

@akusei
Copy link

akusei commented Jan 10, 2024

Overview of the Issue

I recently upgraded packer and ansible to the latest versions and am having an SSH connection issue after the upgrade. When using the remote ansible provisioner in AWS, packer will create the temporary EC2 instance, create the temporary SSH key but then attempt to connect to 127.0.0.1 instead of the newly created EC2 instance. This was working before the ansible and packer upgrade. I believe the problem may be with ansible since this works if I leave packer at the latest version and downgrade ansible to 6.7.0 (or 2.13.13, not sure with their confusing versioning lately)

I've also tried specifying a host_alias in the packer build file and using that for hosts in the ansible playbook but that resulted in the same error. Tried settings use_proxy to false and while that did change the error message to reflect the correct IP instead of 127.0.0.1, it still failed with the same error

Reproduction Steps

  1. Ensure you're using the latest ansible 9.1.0 (core 2.16.2)
  2. Run packer using the ansible provisioner (not local)
  3. Ansible will attempt a connection to 127.0.0.1 instead of the remote host IP

This works properly when using ansible version 6.7.0 (core 2.13.13)

Plugin and Packer version

Packer v1.10.0
Packer Ansible Plugin v1.1.1

ansible [core 2.16.2]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Simplified Packer Buildfile

Packer build file
Ansible configuration file

simplified ansible playbook:

---
- name: Test AMI creation
  become: true
  hosts: all
  gather_facts: true

  pre_tasks:
    - name: Update apt cache if needed
      apt:
        update_cache: true
        cache_valid_time: 86400

  roles:
    - role: my_role

Operating system and Environment details

Ubuntu Jammy 22.04 amd64

Log Fragments and crash.log files

Broken Packer and Ansible 9.1.0 log output
Working Packer and Ansible 6.7.0 log output

After adding the working log output from ansible 6.7.0, it looks like connecting to 127.0.0.1 as the issue may not be related as both log outputs have the same localhost connection being made; so I'm not sure what's going on here, all I know if it works with an older version of ansible but not the latest

@akusei akusei added the bug label Jan 10, 2024
@akusei
Copy link
Author

akusei commented Jan 10, 2024

Looks like this may be related to my use of -oHostKeyAlgorithms=+ssh-rsa and -oPubkeyAcceptedKeyTypes=+ssh-rsa. I will make some changes and re-test

@akusei
Copy link
Author

akusei commented Jan 10, 2024

yeah, this was definitely related to the use of -oHostKeyAlgorithms=+ssh-rsa and -oPubkeyAcceptedKeyTypes=+ssh-rsa. These were added to workaround an issue with Ansible and Ubuntu/SSH but looks to have been changed or fixed in the latest version of Ansible so the options are no longer needed and were causing the error I was seeing. I'll close this since it's not an actual issue but hopefully it helps anyone else who stumbles into this issue

@akusei akusei closed this as completed Jan 10, 2024
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

1 participant