Puppet - 如何使用与主机上的用户相同的用户名在来宾计算机上配置用户 [英] Puppet - how to provision a user on the guest machine with the same username as the user on the host machine

查看:62
本文介绍了Puppet - 如何使用与主机上的用户相同的用户名在来宾计算机上配置用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置 puppet 以使用与提供来宾的主机上的用户的用户名匹配的用户名来配置来宾计算机上的用户? (使用 puppet apply,不是服务器/主)

$ puppet --version
3.4.3
$ vagrant --version
Vagrant 1.7.2

这是我目前尝试过的:

按照此SO answer中的说明,我尝试使用 vagrant/puppet 在来宾计算机上创建用户帐户与主机上的用户帐户匹配.但最终,它没有奏效.不是获取主机用户名,而是创建了一个$user_name"用户.

Following the instructions in this SO answer I tried to use vagrant/puppet to create a user account on the guest machine which matches the user account on the host machine. But ultimately, it didn't work. Instead of getting the host username, a "$user_name" user was created.

流浪文件:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "npalm/mint17-amd64-cinnamon"
  config.vm.hostname = "dev-env"
  config.vm.provider "virtualbox" do |vb|
    vb.name = "dev-env"
    vb.customize ["modifyvm", :id, "--cpus", "2"]
    vb.customize ["modifyvm", :id, "--memory", "1280"]
  end
  config.vm.provision "shell", path: "provisioning/shell/apt-update.sh"
  config.vm.provision "shell", path: "provisioning/shell/puppet.sh"
  config.vm.provision "puppet" do |puppet|
    puppet.facter = {
      "user_name" => ENV['USER']
    }
    puppet.options = "--verbose --debug"
    puppet.manifests_path = "provisioning/puppet/manifests"
    puppet.module_path = "provisioning/puppet/modules"
  end
end

provisioning/shell/apt-update.sh:

#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get install -y aptitude

provisioning/shell/puppet.sh:

#!/usr/bin/env bash
sudo aptitude install -y puppet

provisioning/puppet/manifests/default.pp:

user { '$user_name':
  ensure  => 'present',
  comment => 'developer account',
  home    => '/home/$user_name',
  shell   => '/bin/bash',
  uid     => 643
}
->
file{'$user_name home':
  ensure => 'directory',
  path => '/home/$user_name',
  owner => '$user_name',
  group => '$user_name'
}

实际输出

##############
# Host Machine
##############
$ whoami
axiopisty

###############
# Guest Machine
###############
$ ls -la /home/
total 16
drwxr-xr-x  4 root       root       4096 Dec 17 23:41 .
drwxr-xr-x 24 root       root       4096 Sep 28 20:41 ..
drwxr-xr-x  2 $user_name $user_name 4096 Dec 17 23:41 $user_name
drwxr-xr-x 13 vagrant    vagrant    4096 Sep 28 20:42 vagrant

预期产出

##############
# Host Machine
##############
$ whoami
axiopisty

###############
# Guest Machine
###############
$ ls -la /home/
total 16
drwxr-xr-x  4 root       root       4096 Dec 17 23:41 .
drwxr-xr-x 24 root       root       4096 Sep 28 20:41 ..
drwxr-xr-x  2 axiopisty  axiopisty  4096 Dec 17 23:41 axiopisty
drwxr-xr-x 13 vagrant    vagrant    4096 Sep 28 20:42 vagrant

推荐答案

Puppet 在简单引用时不会解析变量名.要确保对变量名称进行插值,您必须使用 "; 这样你的 puppet 文件中的以下内容就可以工作

Puppet will not resolve variable names when its simple quoted. To make sure interpolation of your variable names is done, you must use "; so the following in your puppet file will work

user { $user_name:
  ensure  => 'present',
  comment => 'developer account',
  home    => "/home/$user_name",
  shell   => '/bin/bash',
  uid     => 643
}
->
file{"$user_name home":
  ensure => 'directory',
  path  => "/home/$user_name",
  owner => "$user_name",
  group => "$user_name"
}

这篇关于Puppet - 如何使用与主机上的用户相同的用户名在来宾计算机上配置用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆