hashicorp / hashicorp/packer-plugin-ansible

Support for builder lxd in combination with ansible

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

Description

#### Community Note

Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

#### Description

The combination of builder type `lxd` is not working with provisioner `ansible`.

The work around is to user the `ansible-local` provisioner, but then you need to install the `ansible` package in the container before being able to run the ansible stuff.

#### Use Case(s)

Create preconfigured LXC images, as you can do for other builder types.

#### Potential configuration

```
{
"builders": [
{
"type": "lxd",
"name": "lxd-focal",
"image": "ubuntu:focal",
"output_image": "focal-apache2",
"publish_properties": {
"description": "Trivial repackage ubuntu:focal with Packer"
}
}
],
"provisioners": [
{
"type": "ansible",
"playbook_file": "./install-apache.yaml"
}
]
}
```

The workaround is to use `ansible-local`, as follows:
```
{
"builders": [
{
"type": "lxd",
"name": "lxd-focal",
"image": "ubuntu:focal",
"output_image": "focal-apache2",
"publish_properties": {
"description": "Trivial repackage ubuntu:focal with Packer"
}
}
],
"provisioners": [
{
"type": "shell",
"inline": ["apt update"]
},
{
"type": "shell",
"inline": ["apt install -y ansible"]
},
{
"type": "ansible-local",
"playbook_file": "./install-apache.yaml"
}
]
}
```

The ansible playbook for this example:
```
---
- name: 'Provision Image With Apache2'
hosts: localhost

tasks:
- name: Install Apache2
ansible.builtin.apt:
name: apache2
state: present
```
#### Potential References

There is a great video by Stéphane Graber on youtube explaining how LXD and Ansible work together. Search for "LXD and Ansible".

Contributor guide

Open the contributing guide

Research direction

The issue identifies the LXD builder and Ansible provisioner as the integration points; start by locating how provisioners connect to the builder and reproduce the provided configuration. Done means the configuration provisions an LXD image with Ansible directly, without installing Ansible inside the container, with coverage for this combination.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, go
Domain
devops, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.