Skip to content

1 char hostname keeps making entries #53

@krisavi

Description

@krisavi

Describe the Bug

When the name of the resource is 1 letter long, it keeps repeating that entry every time puppet agent runs.

Expected Behavior

Not to keep creating new entries and detect that entry already exists.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create host resource with name that is only 1 character
host { 'x':
  ensure       => 'present',
  host_aliases => ['x.my.tld'],
  ip           => '127.0.0.1',
  target       => '/etc/test_hosts',
}
  1. Deploy to machine
  2. Rerun agent
  3. Check resulting file
# HEADER: This file was autogenerated at 2024-04-01 16:28:31 +0300
# HEADER: by puppet.  While it can still be managed manually, it
# HEADER: is definitely not recommended.
127.0.0.1   x   x.my.tld
127.0.0.1   x   x.my.tld
127.0.0.1   x   x.my.tld

Environment

  • Version [Puppet 7.28.0, host_core v1.2.0]
  • Platform [AlmaLinux 8]

Additional Context

No problem with more than 1 character host name.

It seems the regular expression in here expects 1 character that is not #, + nor whitespace and it has to follow with at least 1 character of non whitespace, making it require at least 2 char long host name.

hosts_pattern = '^([0-9a-f:]\S+)\s+([^#\s+]\S+)\s*(.*?)?(?:\s*#\s*(.*))?$'

Potentially fix could be

  hosts_pattern = '^([0-9a-f:]\S+)\s+([^#\s+]+)\s*(.*?)?(?:\s*#\s*(.*))?$'

But should be tested.

Metadata

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