Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chef run fails with executing create action on the 'filesystem' resource #134

Open
David-Pickwell-Hearst opened this issue Dec 19, 2024 · 1 comment

Comments

@David-Pickwell-Hearst
Copy link

👻 Brief Description

When consuming the cookbook version <= 4.0.15, the filesystems are correctly mounted.

With the same code, on Linux instances only, and using version => 4.1.0, the Chef run fails with:

            ================================================================================
             Error executing action `create` on resource 'filesystem[xvdf]'
             ================================================================================
             
             NameError
             ---------
             undefined local variable or method `label' for <truncated>

This is tested in Test Kitchen on EC2 and Azure instances.

🥞 Cookbook version

= 4.1.0

👩‍🍳 Chef-Infra Version

18.5.0

🎩 Platform details

Linux based instances:

  • Amazon 2
  • Amazon 2023 (AMD64 and AARCH64)
  • RHEL8
  • RHEL9
  • Ubuntu 20.04
  • Ubuntu 22.04

In both AWS and Azure

Steps To Reproduce

Converge a node, and call the cookbook (on version >= 4.1.0) as below:

node.default['filesystems'] = JSON.parse(File.read('/etc/chef/tfdisks.json').chomp)

filesystem_create_all_from_key 'filesystems' do
  action :create
  notifies :rename, 'rename_file[tfdisks.json]', :delayed
end

Where the tfdisks.json file has the contents:

{
  "xvdf": {
    "device": "/dev/xvdf",
    "mount": "/temp/mount_0",
    "fstype": "ext4",
    "force": true,
    "mkfs_options": "",
    "options": "nofail,nodev"
  },
  "xvdg": {
    "device": "/dev/xvdg",
    "mount": "/temp/mount_1",
    "fstype": "xfs",
    "mkfs_options": "",
    "options": "nofail,noatime"
  },
  "xvdh": {
    "device": "/dev/xvdh",
    "mount": "/temp/mount_2",
    "fstype": "ext4",
    "force": true,
    "mkfs_options": "",
    "options": "nofail,nodev"
  }
}

🚓 Expected behavior

That the node converges successfully, and the required filesystems are mounted as expected.

➕ Additional context

Add any other context about the problem here. e.g. related issues or existing pull requests.

@David-Pickwell-Hearst
Copy link
Author

This is the more comprehensive output:

-----> Starting Test Kitchen (v3.6.0)
-----> Converging <ec2-amazon-2023>...
       Preparing files for transfer
       Installing cookbooks for Policyfile C:/Repositories/Chef/hts_chef_postbuild/Policyfile.rb using `C:\opscode\chef-workstation\bin\chef-cli.BAT install`
       Installing cookbooks from lock
       Using      chef-client                  12.3.4
       Using      cron                         7.0.28
       Using      filesystem                   4.2.0 
       Using      hts_chef_magic               0.6.0 
       Installing hts_chef_postbuild           1.7.0 
       Using      hts_chef_ssh_authorized_keys 1.1.0 
       Using      line                         4.5.21
       Using      logrotate                    3.0.27
       Using      lvm                          6.2.1 
       Updating policy lock using `C:\opscode\chef-workstation\bin\chef-cli.BAT update`
       Building policy hts_chef_postbuild
       Expanded run list: recipe[hts_chef_postbuild::default]
       Caching Cookbooks...
       Installing hts_chef_postbuild >= 0.0.0 from path
       Using      chef-client                  12.3.4
       Using      line                         4.5.21
       Using      logrotate                    3.0.27
       Using      hts_chef_ssh_authorized_keys 1.1.0
       Using      filesystem                   4.2.0
       Using      hts_chef_magic               0.6.0
       Using      lvm                          6.2.1
       Using      cron                         7.0.28
       
       Lockfile written to C:/Repositories/Chef/hts_chef_postbuild/Policyfile.lock.json
       Policy revision id: 36f915fef34817512b95f2742626d798a59aee844ccba51baf7217075ff56a00
       Preparing dna.json
       Exporting cookbook dependencies from Policyfile C:/Users/DPICKW~1/AppData/Local/Temp/ec2-amazon-2023-sandbox-20241219-38916-46ktww using `C:\opscode\chef-workstation\bin\chef-cli.BAT export`...
       Exported policy 'hts_chef_postbuild' to C:/Users/DPICKW~1/AppData/Local/Temp/ec2-amazon-2023-sandbox-20241219-38916-46ktww
       
       To converge this system with the exported policy, run:
         cd C:/Users/DPICKW~1/AppData/Local/Temp/ec2-amazon-2023-sandbox-20241219-38916-46ktww
         chef-client -z
       Removing non-cookbook files before transfer
       Preparing data_bags
       Preparing secret
       Preparing validation.pem
       Preparing client.rb
       chef installation detected
       install_strategy set to 'once'
       Nothing to install
       Transferring files to <ec2-amazon-2023>
       Chef Infra Client, version 18.5.0
       Patents: https://www.chef.io/patents
       Infra Phase starting
       [2024-12-19T10:00:54+00:00] ERROR: shard_seed: Failed to get dmi property serial_number: is dmidecode installed?
       Using Policyfile 'hts_chef_postbuild' at revision 'd01dc7734245dddba9e14474783da22783b368cb56ebab1cbe712574e614dd6d'
       Resolving cookbooks for run list: ["hts_chef_postbuild::default@1.7.0 (a4e6731)"]
       Synchronizing cookbooks:
         - cron (7.0.28)
         - chef-client (12.3.4)
         - hts_chef_ssh_authorized_keys (1.1.0)
         - filesystem (4.2.0)
         - hts_chef_magic (0.6.0)
         - hts_chef_postbuild (1.7.0)
         - line (4.5.21)
         - logrotate (3.0.27)
         - lvm (6.2.1)
       Installing cookbook gem dependencies:
       Compiling cookbooks...
       Loading Chef InSpec profile files:
       Loading Chef InSpec input files:
       Loading Chef InSpec waiver files:
       [2024-12-19T10:00:55+00:00] WARN: Resource cron_access built into Chef Infra Client is being overridden by the resource from a cookbook. Please upgrade your cookbook or remove the cookbook from your run_list.
       [2024-12-19T10:00:55+00:00] WARN: Resource cron_d built into Chef Infra Client is being overridden by the resource from a cookbook. Please upgrade your cookbook or remove the cookbook from your run_list.
       Recipe: hts_chef_postbuild::tk_create_disk_json
         * bash[create_disk_json_linux_ec2] action run (skipped due to only_if)
         * bash[create_disk_json_linux_azurerm] action run (skipped due to only_if)
       Recipe: hts_chef_postbuild::linux
         * group[sysadmins] action create (up to date)
         Converging 27 resources
       Recipe: hts_chef_postbuild::tk_create_disk_json
         * bash[create_disk_json_linux_ec2] action nothing (skipped due to action :nothing)
         * bash[create_disk_json_linux_azurerm] action nothing (skipped due to action :nothing)
       Recipe: hts_chef_postbuild::logrotate
         * logrotate_app[chef-client] action enable
           * directory[/etc/logrotate.d] action create (up to date)
           * template[/etc/logrotate.d/chef-client] action create (up to date)
            (up to date)
       Recipe: hts_chef_postbuild::linux_mount_disks
         * filesystem_create_all_from_key[filesystems] action create
           * filesystem[xvdf] action create
             * dnf_package[e2fsprogs] action install (up to date)
             
             ================================================================================
             Error executing action `create` on resource 'filesystem[xvdf]'
             ================================================================================
             
             NameError
             ---------
             undefined local variable or method `label' for #<#<Class:0x00007f8f533dd0f8>:0x00007f8f4193cf38...

             <truncated output>

            ...[<filesystem[xvdf] @name: "xvdf" @before: nil @params: nil @provider: nil @allowed_actions: [:nothing, :create, :enable, :mount, :freeze, :unfreeze] @action: [:create, :enable, :mount] @updated: false @updated_by_last_action: false @source_line: "/tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb:36:in `block (2 levels) in class_from_file'" @guard_interpreter: nil @default_guard_interpreter: :default @elapsed_time: 0 @declared_type: :filesystem @cookbook_name: "hts_chef_postbuild" @recipe_name: "linux_mount_disks" @device: "/dev/xvdf" @fstype: "ext4" @mkfs_options: "" @mount: "/temp/mount_0" @options: "nofail,nodev" @force: true>], @insert_after_idx=nil>, @unified_mode=true>, @before_notification_collection={"filesystem[xvdf]"=>[]}, @immediate_notification_collection={"filesystem[xvdf]"=>[]}, @delayed_notification_collection={"filesystem[xvdf]"=>[]}, @delayed_actions=[], @updated_resources=#<Set: {}>, @runner=#<Chef::Runner:0x00007f8f41929780 @run_context=#<Chef::RunContext::ChildRunContext:0x00007f8f41929d70 ...>>>, @action=:create, @assertions={:all_actions=>[], :create=>[]}, @blocked_actions=[]>, @device="/dev/xvdf">
             
             Cookbook Trace: (most recent call first)
             ----------------------------------------
             /tmp/kitchen/cache/cookbooks/filesystem/resources/default.rb:182:in `block in class_from_file'
             /tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb:36:in `block (2 levels) in class_from_file'
             /tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb:32:in `each_key'
             /tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb:32:in `block in class_from_file'
             
             Resource Declaration:
             ---------------------
             # In /tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb
             
       36:     filesystem label do
       37:       label fs['label'] if fs['label']
       38:       device fs['device'] if fs['device']
       39:       vg fs['vg'] if fs['vg']
       40:       file fs['file'] if fs['file']
       41:       uuid fs['uuid'] if fs['uuid']
       42:       fstype fs['fstype'] if fs['fstype']
       43:       mkfs_options fs['mkfs_options'] if fs['mkfs_options']
       44:       recipe fs['recipe'] if fs['recipe']
       45:       package fs['package'] if fs['package']
       46:       sparse fs['sparse'] if fs['sparse']
       47:       size fs['size'] if fs['size']
       48:       stripes fs['stripes'] if fs['stripes']
       49:       mirrors fs['mirrors'] if fs['mirrors']
       50:       mount fs['mount'] if fs['mount']
       51:       options fs['options'] if fs['options']
       52:       user fs['user'] if fs['user']
       53:       group fs['group'] if fs['group']
       54:       mode fs['mode'] if fs['mode']
       55:       pass fs['pass'] if fs['pass']
       56:       dump fs['dump'] if fs['dump']
       57:       force fs['force'] if fs['force']
       58:       # We may not want to do the default action
       59:       if fs['mount'] && fs['nomount']
       60:         # We are not mounting the fs, but we do enable its fstab entry.
       61:         action [:create, :enable]
       62:       elsif fs['mount'] && fs['noenable']
       63:         # We we not enable the fs in fstab, but we do mount it.
       64:         action [:create, :mount]
       65:       elsif fs['nomkfs']
       66:         # We don't create - we just mount and enable - like the mount resource would do.
       67:         action [:enable, :mount]
       68:       elsif fs['mount']
       69:         # Default expected behiavour - create, enable and mount
       70:         action [:create, :enable, :mount]
       71:       else
       72:         # Non-default expected behavior if no mountpoint is given : we only create the filesystem, nothing else.
       73:         action [:create]
       74:       end
       75:     end
       76:   end
       77: end
             
             Compiled Resource:
             ------------------
             # Declared in /tmp/kitchen/cache/cookbooks/filesystem/resources/create_all_from_key.rb:36:in `block (2 levels) in class_from_file'
             
             filesystem("xvdf") do
        action [:create, :enable, :mount]
        default_guard_interpreter :default
        declared_type :filesystem
        cookbook_name "hts_chef_postbuild"
        recipe_name "linux_mount_disks"
        device "/dev/xvdf"
        fstype "ext4"
        mount "/temp/mount_0"
        options "nofail,nodev"
        force true
             end
             
             System Info:
             ------------
             chef_version=18.5.0
             platform=amazon
             platform_version=2023
             ruby=ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
             program_name=/opt/chef/bin/chef-client
             executable=/opt/chef/bin/chef-client
             
           
           ================================================================================
           Error executing action `create` on resource 'filesystem_create_all_from_key[filesystems]'
           ================================================================================
           
           NameError
           ---------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant