Puppet

虛擬定義的 Puppet 重複聲明錯誤

  • May 22, 2014

我正在嘗試使用 puppet 將我的所有使用者添加到系統並將所有使用者添加到單個組中。但是,我不斷得到

Error 400 on SERVER: Duplicate declaration: Group[users] is already declared 
in file *filename*:17 cannot redeclare at *filename* on node *server*

如果我將使用者更改為變數名,例如 $title,它可以正常工作。如何使用像“使用者”這樣的靜態組名來做到這一點?我正在使用以下配置:

**注意:**我可能在下面有錯別字。我不得不重新輸入所有這些,因為我所在的系統沒有 Internet 訪問權限。

define users::virtual ($uid, $realname, $password) {
  user { $title:
    ensure => 'present',
    uid => $uid,
    gid => $'users',
    shell => '/bin/bash',
    home => "/home/${title}",
    comment => $realname,
    password => $password,
    managehome => true,
    require => Group ['users'],
}

  group { 'users':
    ensure => 'present',
    gid => 100,
  }

  file { "/home/${title}":
    ensure => directory,
    owner => $title,
    group => 'users',
    mode => 0700,
    require => [ User[$title], Group['users'] ],
  }
}

class users {
  @users::virtual { 'user1':
    uid => 510,
    realname = 'John Doe',
    password = cyphertext
  }

  @users::virtual { 'user2':
    uid => 511,
    realname = 'Jane Doe',
    password = cyphertext
  }
}

node 'server' {
  realize (Users::Virtual['user1']
  realize (Users::Virtual['user2']
}

群組

$$ ‘users’ $$資源不應該在定義的資源內 users::virtual。您只能創建一次組。將其移至單獨的類。

  group { 'users':
    ensure => 'present',
    gid => 100,
  }

引用自:https://serverfault.com/questions/597651