Puppet error Unknown variable: ‘ssh_user’ for custom resource type in a custom module

I am seeing the following error when my Puppet agent is attempting to retrieve the configuration from the Puppet Server (v8), all running on Redhat OS:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Unknown variable: 'ssh_user'

The error refers to a custom resource type defined in a module called “Users”.

class users::virtual {

    define ssh_user( $user=$name, $uid, $password, $key, $home_dir = 'home' ) {
        user { $user:
            ensure     => present,
            managehome => true,
            uid        => $uid,
            password   => $password,
            home       => "/${home_dir}/${user}"
         }

        ssh_authorized_key { "${user}_key":
            key  => $key,
            type => "ssh-rsa",
            user => $user,
        }

    }

    define ssh_home ($home_dir = 'home') {
      file { "/${home_base_dir}/${name}/.ssh":
          ensure => directory,
          owner  => $name,
          group => $name,
          mode => 0700,
      } ->

      file { "/${home_dir}/${name}/.ssh/id_rsa":
          source => "puppet:///modules/users/${name}/ssh/id_rsa",
          owner  => $name,
          group => $name,
          mode => 0600,
      } ->

      file { "/${home_dir}/${name}/.ssh/id_rsa.pub":
          source => "puppet:///modules/users/${name}/ssh/id_rsa.pub",
          owner  => $name,
          group => $name,
          mode => 0644,
      }
    }
            
    ssh_user { "myuser":
        uid      => 1010,
        password => 'hidden',
        key      => "hidden",
    }

}

Any ideas why this is happening? I removed @ssh_user and tried $ssh_user but see the same error.

4

When you define a class or resource type inside the definition of a different one, it goes into the namespace defined by the container. So, with …

class users::virtual {

    define ssh_user( $user=$name, $uid, $password, $key, $home_dir = 'home' ) {
        user { $user:
            ensure     => present,
            managehome => true,
            uid        => $uid,
            password   => $password,
            home       => "/${home_dir}/${user}"
         }

        ssh_authorized_key { "${user}_key":
            key  => $key,
            type => "ssh-rsa",
            user => $user,
        }

    }

… the (fully-qualified) name of the defined type is users::virtual::ssh_user.

In Puppet 3 and earlier, Puppet would attempt to resolve class and defined type names such as ssh_user relative to the innermost local namespace first, working its way outward until it found a namespace wherein the name was defined, or else did not find it even as a top-scope name. That behavior was dropped in Puppet 4. Since then, you always need to refer to classes and defined types by their fully-qualified names. This is one of the lesser of a number of reasons why you should not nest class and defined type definitions.

The best solution, then, would be to lift the ssh_user type to its own file, presumably modules/users/manifests/ssh_user.pp. In that case, the name by which you reference it would be users::ssh_user:

    users::ssh_user { "myuser":
        uid      => 1010,
        password => 'hidden',
        key      => "hidden",
    }

On the other hand, if you stick with the nested definition then you’ll still need to refer to the type via its full name, but that name will be users::virtual::ssh_user, as already described:

    users::virtual::ssh_user { "myuser":
        uid      => 1010,
        password => 'hidden',
        key      => "hidden",
    }

If you want keep the same fuilly-qualified name when you lift the type to its own file, then you can instead put it in modules/users/manifests/virtual/ssh_user.pp.

Wherever you put the type, if you lift it into its own file then you should define it with its fully-qualified name. For example,

modules/users/manifests/ssh_user.pp

define users::ssh_user( $user=$name, $uid, $password, $key, $home_dir = 'home' ) {
  # ...
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật