solo-io / packer-plugin-arm-image

Packer plugin for ARM images
Apache License 2.0
425 stars 104 forks source link

Error: unrecognized arguments: playbook.yml #156

Closed shanduur closed 1 year ago

shanduur commented 1 year ago

Related to https://github.com/hashicorp/packer-plugin-ansible/issues/134

Overview of the Issue

While trying to build image with packer, at Ansible provisioner step, the following log is created, and packer exits with RC=1:

==> arm-image.ubuntu-2204: Executing Ansible: ansible-playbook -e packer_build_name="ubuntu-2204" -e packer_builder_type=arm-image -vvvvv --connection=chroot --become-user=root --extra-vars ansible_host=/tmp/armimg-2292410357 --extra-vars default_username=admin --extra-vars default_password=***** -e ansible_ssh_private_key_file=/tmp/ansible-key1021651395 -i /tmp/packer-provisioner-ansible802100546 /home/shanduur/Repos/deployment/images/rpi-ubuntu-22.04/ansible/playbooks/user.yml
.
.
.
    arm-image.ubuntu-2204: ansible-playbook: error: unrecognized arguments: /home/shanduur/Repos/deployment/images/rpi-ubuntu-22.04/ansible/playbooks/user.yml

Reproduction Steps

Create the following folder structure:

.
├── Makefile
├── rpi-ubuntu-22.04
│   ├── ansible
│   │   └── playbooks
│   │       └── user.yml
│   └── img.pkr.hcl
└── variables.pkrvars.hcl

Paste the content of the files below to the appropriate files. Run make rpi-ubuntu-22.04

Plugin and Packer version

From packer version

Simplified Packer Buildfile

packer {
  required_plugins {
    ansible = {
      version = ">= 1.0.2"
      source  = "github.com/hashicorp/ansible"
    }
  }
}

variable "default_username" {
  type    = string
  default = "admin"
}

variable "default_password" {
  type    = string
  default = "Ch@ngeme1"
}

source "arm-image" "ubuntu-2204" {
  iso_url = "https://cdimage.ubuntu.com/releases/22.04.1/release/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img.xz"
  iso_checksum = "5d0661eef1a0b89358159f3849c8f291be2305e5fe85b7a16811719e6e8ad5d1"
  target_image_size = "${var.target_image_size}"
}

build {
  sources = ["source.arm-image.ubuntu-2204"]

  provisioner "file" {
    source = "templates/"
    destination = "/apps"
  }

  provisioner "ansible" {
    playbook_file = "ansible/playbooks/user.yml"

    ansible_env_vars = [
      "PYTHONUNBUFFERED=1",
    ]

    extra_arguments = [
      "--connection=chroot",
      "--become-user=root",
      "--extra-vars ansible_host=${build.MountPath}",
      "--extra-vars default_username=${var.default_username}",
      "--extra-vars default_password=${var.default_password}"
    ]
  }
}

Playbook file, located at ansible/playbooks/user.yml:

- hosts: all
  tasks:
    - name: Ensure that 'default_username' is defined
      fail: msg="Bailing out. This play requires 'default_username'"
      when: default_username is undefined

    - name: Ensure that 'default_password' is defined
      fail: msg="Bailing out. This play requires 'default_password'"
      when: default_password is undefined

    - name: Delete default "ubuntu" user
      ansible.builtin.user:
        name: ubuntu
        state: absent
        remove: true
        force: true

    - name: Create new user
      ansible.builtin.user:
        name: '{{ default_username }}'
        password: '{{ default_password }}'

Simplified Makefile:

PKR_VARIABLES=../variables.pkrvars.hcl
PKR_CONFIG=img.pkr.hcl

.PHONY: rpi-ubuntu-22.04
rpi-ubuntu-22.04:
    TARGET=rpi-ubuntu-22.04 make img

.PHONY: img
img:
    cd ${TARGET} && \
    PACKER_LOG=1 sudo -E packer init ${PKR_CONFIG} && \
    PACKER_LOG=1 sudo -E packer build \
        -var-file ${PKR_VARIABLES} \
        ${PKR_CONFIG}

Operating system and Environment details

$ uname -a
Linux rocky.dev 4.18.0-372.19.1.el8_6.x86_64 #1 SMP Tue Aug 2 16:19:42 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.5 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.5"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.5 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
$ ansible --version
ansible [core 2.14.1]
  config file = None
  configured module search path = ['/home/shanduur/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/shanduur/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/shanduur/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Nov  9 2021, 13:31:27) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] (/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Log Fragments and crash.log files

packer.log

rtertiaer commented 1 year ago

@shanduur is this resolved? from your upstream bug it looks like it is.