Ansible provisionner hangs

Hi,

I’m sorry but I have problem from long time with packer.
Provisionning hangs, I have to “ctrl+c” to exit.

Today, I try on fresh Ubuntu Focal install, but same problem.

Ubuntu 20.04
Packer 1.60
Ansible 2.9.11

json:

{
    "variables": {
    },
    "builders": [
        {
          "type": "lxd",
          "name": "ubuntu-2004-qw",
          "image": "ubuntu-minimal:focal",
          "output_image": "ubuntu-2004-qw",
          "publish_properties": {
            "description": "Image LXD ubuntu bionic ansible ready"
          }
      }
    ],
    "provisioners": [
      {
        "type": "ansible",
        "user": "root",
        "playbook_file": "config.yml",
        "extra_arguments": ["-vvvv"]
      }
    ]
}

playbook:

- hosts: default
  become: yes
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
  gather_facts: no
  tasks:
    - name: Ajout user ansible avec cle ssh
      user:
        name: ansible
        comment: Ansible user
        system: yes

    - name: Set up multiple authorized keys
      authorized_key:
        user: ansible
        state: present
        key: '{{ item }}'
      loop:
        - ssh-xxxxxx
        - ssh-xxxxxx

console:

PACKER_DEBUG=1 packer build ansible.json
ubuntu-2004-qw: output will be in this color.

==> ubuntu-2004-qw: Creating container...
==> ubuntu-2004-qw: Provisioning with Ansible...
    ubuntu-2004-qw: Setting up proxy adapter for Ansible....
==> ubuntu-2004-qw: Executing Ansible: ansible-playbook -e packer_build_name=ubuntu-2004-qw -e packer_builder_type=lxd -e packer_http_addr=ERR_HTTP_ADDR_NOT_IMPLEMENTED_BY_BUILDER -vvvv -e ansible_ssh_private_key_file=/tmp/ansible-key074176145 -i /tmp/packer-provisioner-ansible384870076 /home/ansible/config.yml
    ubuntu-2004-qw: ansible-playbook 2.9.11
    ubuntu-2004-qw:   config file = None
    ubuntu-2004-qw:   configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ubuntu-2004-qw:   ansible python module location = /home/ansible/.local/lib/python3.8/site-packages/ansible
    ubuntu-2004-qw:   executable location = /home/ansible/.local/bin/ansible-playbook
    ubuntu-2004-qw:   python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
    ubuntu-2004-qw: No config file found; using defaults
    ubuntu-2004-qw: setting up inventory plugins
    ubuntu-2004-qw: host_list declined parsing /tmp/packer-provisioner-ansible384870076 as it did not pass its verify_file() method
    ubuntu-2004-qw: script declined parsing /tmp/packer-provisioner-ansible384870076 as it did not pass its verify_file() method
    ubuntu-2004-qw: auto declined parsing /tmp/packer-provisioner-ansible384870076 as it did not pass its verify_file() method
    ubuntu-2004-qw: Parsed /tmp/packer-provisioner-ansible384870076 inventory source with ini plugin
    ubuntu-2004-qw: Loading callback plugin default of type stdout, v2.0 from /home/ansible/.local/lib/python3.8/site-packages/ansible/plugins/callback/default.py
    ubuntu-2004-qw:
    ubuntu-2004-qw: PLAYBOOK: config.yml ***********************************************************
    ubuntu-2004-qw: Positional arguments: /home/ansible/config.yml
    ubuntu-2004-qw: verbosity: 4
    ubuntu-2004-qw: connection: smart
    ubuntu-2004-qw: timeout: 10
    ubuntu-2004-qw: become_method: sudo
    ubuntu-2004-qw: tags: ('all',)
    ubuntu-2004-qw: inventory: ('/tmp/packer-provisioner-ansible384870076',)
    ubuntu-2004-qw: extra_vars: ('packer_build_name=ubuntu-2004-qw', 'packer_builder_type=lxd', 'packer_http_addr=ERR_HTTP_ADDR_NOT_IMPLEMENTED_BY_BUILDER', 'ansible_ssh_private_key_file=/tmp/ansible-key074176145')
    ubuntu-2004-qw: forks: 5
    ubuntu-2004-qw: 1 plays in /home/ansible/config.yml
    ubuntu-2004-qw:
    ubuntu-2004-qw: PLAY [default] *****************************************************************
    ubuntu-2004-qw: META: ran handlers
    ubuntu-2004-qw:
    ubuntu-2004-qw: TASK [Ajout user ansible avec cle ssh] *****************************************
    ubuntu-2004-qw: task path: /home/ansible/config.yml:8
    ubuntu-2004-qw: <127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: root
    ubuntu-2004-qw: <127.0.0.1> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=37759 -o 'IdentityFile="/tmp/ansible-key074176145"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/d9b3ed108b 127.0.0.1 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''

And it’s stuck.

What I can do?
Thanks

Exactly the same problem here, with 2 playbooks, except that it is always the last task of the last playbook that fails, and it hangs for 2 hours, sharp.
I tried swapping them to no avail.
Downgraded to ansible 2.7.10 => Nope
Packer 1.4.1 => 1.6.1 => Nope

Solution: only one wrapping playbook with multiple roles => works a s a charm

@ quanticware try setting "no_proxy": "true" in the ansible provisioner config.

1 Like

I’m facing the exact same issue and tried adding:

no_proxy = "true"

But got:

Unsupported argument; An argument named "no_proxy" is not expected here

Then I tried:

use_proxy = "false"

and no longer had a hanging build, but got:

Load key "/tmp/ansible-key106956624": invalid format\r\nubuntu@<ipaddress>: Permission denied (publickey,password).\r\n

So this is definitely related, but now I need to figure out how to set up these keys correctly :slight_smile:

Ah, writing config options from memory is never a good idea; you were right that the option I was thinking of is use_proxy

That second error looks like a line ending issue with the \r\n

Try converting your key to use unix style endings?

I actually didn’t have any key defined (so not line ending related) and it gave me that (slightly misleading) error. But when I added:

    extra_arguments  = [
      "--extra-vars", "ansible_ssh_pass=${var.ssh_password}"
    ]

everything started working just fine.
I noticed Ansible Can't SSH When SSH Communicator Uses Password · Issue #6 · hashicorp/packer-plugin-ansible · GitHub is still open, so I guess it’s a known issue that eventually will get fixed?

1 Like