hashicorp / hashicorp/packer-plugin-lxd
lxd / salt masterless: packer is unable to copy states tree correctly: bad directories (/root and / confusion)
- Dominant language
- Go
- Stars
- 14
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
_This issue was originally opened by @gaetanquentin as hashicorp/packer#10023. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._
#### Overview of the Issue
packer salt module can't copy states tree when used with lxd: bad directories
#### Reproduction Steps
PACKER_LOG=1 packer build -on-error=ask -var-file=../../lab/01_common/default-variables.json lxd-ubuntu-20.04-saltmaster-2020.json
### Packer/salt/lxd versions
packer >= 1.6.0: currently 1.6.4
salt version: 3001.1
lxd version: 4.6 (snap)
### Simplified Packer Buildfile
variables:
"salt_local_pillars_dir": "/home/gquentin/Work/repositories/git/automation/Provisionners/SaltStack/pillar",
"salt_remote_pillars_dir": "/srv/pillar",
"salt_local_states_dir": "/home/gquentin/Work/repositories/git/automation/Provisionners/SaltStack/states",
"salt_remote_states_dir": "/srv",
"salt_temp_config_dir": "/tmp/salt"
other:
{
"builders": [
{
"type": "lxd",
"name": "ubuntu-20-04",
"image": "images:ubuntu/20.04",
"output_image": "ubuntu-20-04",
"publish_properties": {
"description": "Ubuntu focal amd64 with saltmaster 3001 built with packer "
},
"profile": "default",
"launch_config": {
"security.privileged": "false"
}
}
],
[ ..]
{
"type": "salt-masterless",
"local_state_tree": "{{user `salt_local_states_dir`}}",
"remote_state_tree": "{{user `salt_remote_states_dir`}}",
"local_pillar_roots": "{{user `salt_local_pillars_dir`}}",
"remote_pillar_roots": "{{user `salt_remote_pillars_dir`}}",
"temp_config_dir": "{{user `salt_temp_config_dir`}}",
"custom_state": "sys.tools,sys.locale,sys.sysctl,sys.network,apps.configmanager.salt.master,apps.versioncontrol.git",
"skip_bootstrap": "true",
"bootstrap_args": "-x python3 stable 3001.1 ",
"pause_before": "20s"
},
[ ..]
### Operating system and Environment details
Host: ubuntu 20.04
lxd container image: ubuntu 20.04
### Log Fragments and crash.log files
```
ubuntu-20-04: Uploading local state tree: /home/gquentin/Work/repositories/git/automation/Provisionners/SaltStack/states
2020/10/01 13:20:45 packer-builder-lxd plugin: lxc file push --debug -pr /home/gquentin/Work/repositories/git/automation/Provisionners/SaltStack/states packer-ubuntu-20-04/states
2020/10/01 13:20:45 packer-builder-lxd plugin: Running cp command: lxc file push --debug -pr /home/gquentin/Work/repositories/git/automation/Provisionners/SaltStack/states packer-ubuntu-20-04/states
=> here you can see packer copying states dir in the root (/) of target container
ubuntu-20-04: Moving states to /tmp/salt/states
2020/10/01 13:20:47 packer-builder-lxd plugin: Executing with lxc exec in container: packer-ubuntu-20-04 sudo sudo mv 'states' '/tmp/salt/states'
2020/10/01 13:20:47 packer-builder-lxd plugin: Executing lxc exec: /bin/sh []string{"/bin/sh", "-c", "lxc exec packer-ubuntu-20-04 -- /bin/sh -c \"sudo sudo mv 'states' '/tmp/salt/states'\""}
==> ubuntu-20-04: mv: cannot stat 'states': No such file or directory
=> here you can see in "sudo mv states /tmp/salt/states" that packer try to move states from /root/states and not /states since default lxc exec env is user root in /root
more theses directories are not theses specified in input variables
```
Regards
Contributor guide
Research direction
Start with the salt-masterless flow that uploads the state tree through `lxc file push` and then moves it via `lxc exec`; reproduce the command shown with the LXD builder and the provided variables. Trace how the working directory and destination paths are formed. Done means the states and pillar trees are copied to the configured remote paths without `/root` versus `/` mismatches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100