hashicorp / hashicorp/packer-plugin-ansible

Regex check instead of YAML parsing causes collections installation to be skipped

Open
#239 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
64
Forks
40
PR merge metrics
No merged PRs in 30d

Description

#### Overview of the Issue
[`provisioner.go`](https://github.com/hashicorp/packer-plugin-ansible/blob/d4b96c2/provisioner/ansible-local/provisioner.go#L509-L510) uses a simple `regexp.Match()` to evaluate the requirements file instead of unmarshalling/parsing the YAML file into a struct:
https://github.com/hashicorp/packer-plugin-ansible/blob/d4b96c2ecbc653be23e55ebe6f8af805b3c79422/provisioner/ansible-local/provisioner.go#L509-L510

If the requirements file is formed as JSON (which is a valid YAML subset), this will lead to it not detecting the `roles` and `collections` keys of the requirements, which in turn results in only the roles, but not the collections installed.

#### Reproduction Steps

- convert an existing and working requirements file, which also contains collections to JSON (e.g. just https://jsonformatter.org/yaml-to-json)
- execute Packer and observe the Ansible Galaxy operations and their results

### Plugin and Packer version

Packer v1.14.0
Packer Plugin Ansible v.1.1.3

Contributor guide

Open the contributing guide

Research direction

Start in provisioner/ansible-local/provisioner.go around lines 509-510, where the requirements file is checked with regexp.Match(). Reproduce the issue using a JSON-formatted requirements file containing roles and collections, then execute Packer and inspect the Ansible Galaxy operations. Done means the collections are detected and installed along with the roles.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, go
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.