hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.03k stars 3.32k forks source link

[Chef-solo] roles_path is ignored by chef-solo provisionner #3298

Closed sogos closed 3 years ago

sogos commented 8 years ago

When i use this snippet

{
    "type": "chef-solo",
    "install_command": "curl -L https://www.chef.io/chef/install.sh | {{if .Sudo}}sudo {{end}}bash -s -- -v 12.6.0",
    "cookbook_paths": ["{{user `cookbook_paths`}}"],
    "environments_path": "{{user `environments_path`}}",
    "roles_path":  "{{user `chef_roles_path`}}",
    "data_bags_path": "{{user `data_bags_path`}}",
    "encrypted_data_bag_secret_path": "{{user `encrypted_data_bag_secret_path`}}",
    "chef_environment": "build",
    "run_list": ["role[webserver]"]
}

The solo.rb is not filled with roles_path and role directory is not uploaded to staging_directory

    virtualbox-iso: Creating directory: /tmp/packer-chef-solo
    virtualbox-iso: Creating directory: /tmp/packer-chef-solo/cookbooks-0
    virtualbox-iso: Creating directory: /tmp/packer-chef-solo/data_bags
    virtualbox-iso: Creating configuration file 'solo.rb'
    virtualbox-iso: Creating JSON attribute file
    virtualbox-iso: Executing Chef: sudo chef-solo --no-color -c /tmp/packer-chef-solo/solo.rb -j /tmp/packer-chef-solo/node.json
    virtualbox-iso: [2016-03-01T16:34:45+01:00] INFO: Forking chef instance to converge...
    virtualbox-iso: [2016-03-01T16:34:45+01:00] INFO: *** Chef 12.6.0 ***
    virtualbox-iso: [2016-03-01T16:34:45+01:00] INFO: Chef-client pid: 1312
    virtualbox-iso: [2016-03-01T16:34:47+01:00] INFO: Setting the run_list to ["role[ugo-vm]"] from CLI options
    virtualbox-iso: [2016-03-01T16:34:47+01:00] ERROR: Role webserver (included by 'top level') is in the runlist but does not exist. Skipping expand.

I use "packer_0.9.0_darwin_amd64"

Thanks

sogos commented 8 years ago

If I put a value directly in config for roles_path and not in command line variable like:

  "{{user `chef_roles_path`}}"

the directory is inspected before the run and roles are well uploaded

So the bug is : we can't provide roles_path as User var from command line

Thanks

cbednarski commented 8 years ago

Thanks for clarifying the failure case here. You might be able to hack around this problem by customizing the execute_command. Another approach is to generate that part of the template using python, ruby, or sed before you run the build.

sogos commented 8 years ago

Thanks, it's a good idea for the moment

I can add that "environments_path" also don't work when User var

fasmat commented 5 years ago

Hi @sogos, hi @cbednarski,

I've been running into the same problem recently. I'm using packer version 1.0.4, but it also seems to fail in 1.4.0. Here is my template file:

{
    "variables": {
        "export_path": "{{env `DOCKER_IMAGE_PATH`}}",
        "chefdk_version": "{{env `CHEFDK_VERSION`}}",
        "chef_path": "{{env `CHEF_PATH`}}"
    },
    "builders": [
        {
            "name": "docker-container",
            "type": "docker",
            "image": "ubuntu:bionic",
            "export_path": "{{user `export_path`}}"
        }
    ],
    "provisioners": [
        {
            "type": "shell",
            "inline": [
                "apt-get update",
                "DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends curl sudo ca-certificates dnsutils"
            ]
        },
        {
            "type": "chef-solo",
            "install_command": "curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chefdk -c stable -v {{user `chefdk_version`}}",
            "cookbook_paths": [
                "/home/vagrant/repo/tools/chef/berks-cookbooks",
                "/home/vagrant/repo/tools/chef/cookbooks"
            ],
            "roles_path": "/home/vagrant/repo/tools/chef/roles",
            "run_list": [
                "role[common]"
            ]
        }
    ]
}

The roles directory contains a file called common.json, but it seems like this file is not uploaded to the container before chef is being executed.

nywilken commented 3 years ago

Hello folks, thanks for opening up this issue. Apologies that we've not had the chance to dive further into this issue. If you've managed to resolve your problem we encourage you to leave comment for others who may experience this issue in the future.

With that said, this is one of our community maintained plugins, which we have recently flagged as unmaintained. If you are interested in contributing or taking ownership of this plugin, please reach out to us at packer@hashicorp.com.

ghost commented 3 years ago

This issue has been automatically migrated to hashicorp/packer-plugin-chef#16 because it looks like an issue with that plugin. If you believe this is not an issue with the plugin, please reply to hashicorp/packer-plugin-chef#16.

ghost commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.