Subtubes
Subtubes

Reputation: 16873

Ansible with Packer

I am trying to get packers ansible provisioner to use a username and password but the configuration with ansible keeps stalling because the authentication step fails.

Here is my Packer Ansible provisioner script.

    {
  "type": "ansible",
  "user": "pi",
  "playbook_file": "playbook.yml",
  "extra_arguments": [
    "--extra-vars",
    "ansible_python_interpreter=/usr/bin/python3",

    "--extra-vars",
    "ansible_user=pi",

    "--extra-vars",
    "ansible_ssh_pass=raspberry",

    "-vvv"
  ]
}

I'm a t a complete loss why this does not work.

The output where it gets stuck is as follows.

    armpi: ==> arm-image: Executing Ansible: ansible-playbook --extra-vars packer_build_name=arm-image packer_builder_type=arm-image -i /tmp/packer-provisioner-ansible288108417 playbook.yml -e ansible_ssh_private_key_file=/tmp/ansible-key528332842 --extra-vars ansible_python_interpreter=/usr/bin/python3 --extra-vars ansible_ssh_user=pi --extra-vars ansible_ssh_pass=raspberry -vvv

looks like it is trying to use a ansible_ssh_private_key_file=/tmp/ansible-key528332842 but I dont want it to use that I really just want it to log in with username and password.

Upvotes: 1

Views: 3680

Answers (1)

Rickard von Essen
Rickard von Essen

Reputation: 4278

From the top of the ansible provisioner documentation:

The ansible Packer provisioner runs Ansible playbooks. It dynamically creates an Ansible inventory file configured to use SSH, runs an SSH server, executes ansible-playbook, and marshals Ansible plays through the SSH server to the machine being provisioned by Packer.

Note: Any remote_user defined in tasks will be ignored. Packer will always connect with the user given in the json config for this provisioner.

What you are trying to do is not possible with the ansible provisioner. But you can achieve the thing you try to do by running ansible with the shell-local provisioner.

(To get the IP address of the VM to use in the Ansible inventory you can follow the general patter I sugest in this post.)

Upvotes: 5

Related Questions