Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-2289

Puppet will purge the /etc/hosts if it have some invalid lines

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 3.4.3, PUP 3.6.2
    • Fix Version/s: PUP 4.0.0
    • Component/s: Types and Providers
    • Labels:
      None
    • Environment:
    • Template:
    • Story Points:
      0

      Description

      normally, i use puppet resource host puppet ip=xxx.xxx.xxx.xxx can add/set a domain name resolution into /etc/hosts. like this:

      [root@puppet ~]# cat /etc/hosts
      127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
      ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
      [root@puppet ~]# puppet resource host puppet ip=172.16.94.128
      Notice: /Host[puppet]/ensure: created
      host { 'puppet':
        ensure => 'present',
        ip     => '172.16.94.128',
        target => '/etc/hosts',
      }
      [root@puppet ~]# cat /etc/hosts
      # HEADER: This file was autogenerated at Wed Apr 16 17:57:19 +0800 2014
      # HEADER: by puppet.  While it can still be managed manually, it
      # HEADER: is definitely not recommended.
      127.0.0.1	localhost	localhost.localdomain localhost4 localhost4.localdomain4
      ::1	localhost	localhost.localdomain localhost6 localhost6.localdomain6
      172.16.94.128	puppet
      

      but if there have some invalid text in /etc/hosts, link '=' or ', ,', puppet will purge that file and create a new one.

      [root@puppet ~]# cat /etc/hosts
      # HEADER: This file was autogenerated at Wed Apr 16 17:57:19 +0800 2014
      # HEADER: by puppet.  While it can still be managed manually, it
      # HEADER: is definitely not recommended.
      127.0.0.1	localhost	localhost.localdomain localhost4 localhost4.localdomain4
      ::1	localhost	localhost.localdomain localhost6 localhost6.localdomain6
      ==
      [root@puppet ~]# puppet resource host puppet ip=172.16.94.128
      Error: Could not prefetch host provider 'parsed': Could not parse line "==" at /etc/hosts:4
      Notice: /Host[puppet]/ensure: created
      host { 'puppet':
        ensure => 'present',
        ip     => '172.16.94.128',
        target => '/etc/hosts',
      }
      [root@puppet ~]# cat /etc/hosts
      # HEADER: This file was autogenerated at Wed Apr 16 18:00:59 +0800 2014
      # HEADER: by puppet.  While it can still be managed manually, it
      # HEADER: is definitely not recommended.
      172.16.94.128	puppet
      

      i checked the source code, it have three rules to check if the lines in /etc/hosts invalid.

      /^#/
      /^\s*$/
      /^(\S+)\s+(\S+)\s*(.*?)?(?:\s*#\s*(.*))?$/
      

      but i think if puppet checked out there is some invalid lines, it should report error and exit, not keep going and purge my hosts file

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                liucy1983 liucy
                QA Contact:
                Eric Thompson
              • Votes:
                8 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support