Skip to content

Windows: When adding many host entries, some fail with "Permission denied" errors #9528

Open
@dhs-rec

Description

Describe the Bug

When adding many host entries on Windows, using host resources, some sometimes fail with

Puppet::Util::FileType::FileTypeFlat could not write C:/Windows/System32/drivers/etc/hosts: Permission denied @ rb_sysopen - C:/Windows/System32/drivers/etc/hosts

while the other ones are added just fine.

Expected Behavior

All host entries should be added w/o error

Steps to Reproduce

Use the following class to add many host entries to a new Windows node (possibly in a setup with at least 20-30 other nodes):

class hosts {
  # Let each host create a host entry as exported resource
  $nic = $facts['networking']['primary']
  $ip = $facts['networking']['interfaces'][$nic]['ip']

  @@host { $facts['networking']['fqdn']:
    comment      => 'Host entry generated by Puppet',
    host_aliases => [$facts['networking']['hostname']],
    ip           => $ip,
    tag          => ['HOST_RECORD'],
  }

  # Collect all exported host records and add them to (C:/Windows/System32/drivers)/etc/hosts
  Host <<| tag == 'HOST_RECORD' |>> { ensure => present }
}

Environment

  • Version: 7
  • Platform: Windows Server 20xx

Additional Context

Could work around/fix the problem with the following patch:

*** /usr/lib/ruby/vendor_ruby/puppet/util/filetype.rb   2023-02-07 22:38:26.000000000 +0100
--- Windows/filetype.rb 2024-11-28 10:46:10.605288810 +0100
***************
*** 127,132 ****
--- 127,133 ----
        File.chmod(@default_mode, tf.path) if @default_mode
        FileUtils.cp(tf.path, @path)
        tf.close
+       sleep(0.1) if Facter.value(:kernel) == 'windows'
        # If SELinux is present, we need to ensure the file has its expected context
        set_selinux_default_context(@path)
      end

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions