Chef Error while installing multiple packages using custom attributes

Asim Baig

I am trying to install multiple packages with Chef's 'package' resource by using custom attributes. When I try:

package %w(python3 python3-pip) do
action :install
end

The above code works fine for me, but same code is giving error while trying with custom attributes.

Please have a look-

My recipe_code :

package %w(node['python']['pkg_name'] node['python-pip']['pkg_name']) do
    action :install
end

Attribute_code :

default['python']['pkg_name'] = 'python3'
default['python-pip']['pkg_name'] = 'python3-pip'

Error log:

  Compiling Cookbooks...
   Converging 3 resources
   Recipe: odoo_setup::odoo_linux
     * apt_update[update_ubuntu_pkg_lib] action update
       * directory[/var/lib/apt/periodic] action create (up to date)
       * directory[/etc/apt/apt.conf.d] action create (up to date)
       * file[/etc/apt/apt.conf.d/15update-stamp] action create_if_missing (up to date)
       * execute[apt-get -q update] action run
         - execute ["apt-get", "-q", "update"]
       - force update new lists of packages
     * apt_package[node['python']['pkg_name'], node['python-pip']['pkg_name']] action install
       * No candidate version available for node['python']['pkg_name'], node['python-pip']['pkg_name']
       ================================================================================
       Error executing action `install` on resource 'apt_package[node['python']['pkg_name'], node['python-pip']['pkg_name']]'
       ================================================================================

       Chef::Exceptions::Package
       -------------------------
       No candidate version available for node['python']['pkg_name'], node['python-pip']['pkg_name']

       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cache/cookbooks/odoo_setup/recipes/odoo_linux.rb

        32: package %w(node['python']['pkg_name'] node['python-pip']['pkg_name']) do
        33: # package node['python']['pkg_name'] do
        34:     action :install
        35: end
        36:
Draco Ater

%w is a percent literal in Ruby, that creates an array from separate words in the brackets. Your first example works, because

%w(python3 python3-pip) == ['python3', 'python3-pip']

But this %w does not support string interpolation. Your second example is actually:

%w(node['python']['pkg_name'] node['python-pip']['pkg_name']) == ["node['python']['pkg_name']", "node['python-pip']['pkg_name']"]

See how your values are actually strings, not variables. If you need to use variables, use ordinary Array initialization, and not %w literal.

package [node['python']['pkg_name'], node['python-pip']['pkg_name']]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error while installing packages

Installing rpm packages using chef (with dependencies)

Syntax Error while installing packages in jenkins

Error While installing perl Packages in Freebsd?

Dependencies error while installing packages with NuGet

Chef custom attributes

Permission issues while using and installing Python packages

Error while installing packages using yarn or npm, `Request failed \"401 Unauthorized`

Using attributes in Chef

Error installing packages using renv::restore()

Installing packages using pip give SSL error

Error while installing hashicorp/custom: provider registry

Installing custom packages on Linux

Getting error while installing tizen wearable packages from update manager

Package retrieving error is occurred while installing Chocolatey packages

Dpkg command fails while installing packages due to invalid user error

Broken packages error while installing zookeeper-server

pip install traceback error while installing packages in Python

ERROR: Could not install packages due to an EnvironmentError while installing tensorflow

Getting error while installing LLVM Ubuntu nightly packages

Python Pycharm error while installing packages from pypi on Ubuntu

Installing multiple packages with composer?

Missing header files while installing packages using pip

Errors while installing Android Studio packages using PPA

Why installing custom python packages using RUN in Dockerfile does not work?

Using attributes in Chef Solo JSON

Installing tomcat on windows using CHEF

Error while installing magento using xampp

Error while installing perl module using cpanm

TOP Ranking

HotTag

Archive