How to set up custom bash environment for differen

2019-06-19 08:05发布

问题:

I'm just getting started with puppet (and vagrant) to set up the development environment for our team, which consists of 8+ developers, each of which have their particular bash configuration, etc. I've got all the software installed on the system to quickly deploy new development virtual machines, but I'm not sure the best way to set up the development environment for each particular user in an automated way (we will end up having several development environments and it would be convenient to write this once and be done).

For example, I'd like to set up a user joe, clone Joe's configuration repo from github, and then run a script in that github repository to set up the environment for Joe. Any suggestions for how to do this for Joe as well as Jimmy, James, Julie, Jane, Jim, Jake, and Jimbo?

In case its any help, the development machines will almost certainly be ubuntu systems.

回答1:

In addition to @Matt's suggestion, I created a custom puppet module that instantiates the configuration environment for each individual based on their github preferences. The resulting puppet module users looks something like this:

users/
├── manifests
│   ├── init.pp      # base level configurations for all users
│   ├── jake.pp      # custom setup for jake
│   ├── james.pp     # custom setup for james
│   ├── jane.pp      # custom setup for jane
│   ├── jim.pp       # custom setup for jim
│   ├── jimbo.pp     # custom setup for joe
│   ├── jimmy.pp     # custom setup for jimmy
│   ├── joe.pp       # custom setup for julie
│   └── julie.pp     # custom setup for jimbo
└── templates

The relevant tidbit is in the custom setup files for each user. For example, here's what jim.pp might look like:

class users::jim {

  # make sure that all base configuration in init.pp is set up first
  require users

  # add the user here
  user { 'jim':
    # comment    => 'Dean Malmgren',
    home       => '/home/jim',
    shell      => '/bin/bash',
    uid        => 201,
    managehome => 'true',
    groups     => ['sudo', 'vagrant'],
    provider   => 'useradd',
    password   => '$6$kxHLEuHW$78m3zHVLu0XUUDaU4bT.PEg./FfcloJiWml',
  }

  # clone the repository the first time
  exec { 'jim-clone-dotfiles':
    command => 'git clone git://github.com/jim/dotfiles.git && python dotfiles/create_softlinks.py',
    cwd     => '/home/jim',
    creates => '/home/jim/dotfiles',
    user => 'jim',
    group => 'jim',
    require => [ Package['git'] ],
  }

  # fetch and update if jim decides to update his dotfiles repo
  exec { 'jim-update-dotfiles':
    command => 'git merge --ff-only origin/master && python create_softlinks.py',
    cwd     => '/home/jim/dotfiles',
    unless => 'git fetch && git diff --exit-code origin/master',
    user => 'jim',
    group => 'jim',
    require => Exec['jim-clone-dotfiles'],
  }
}


回答2:

You could use a puppet fact in the vagrant file to set the username and pass this through to your puppet manifests. Something like the following:

Vagrant.configure("2") do |config|
  config.vm.provision :puppet do |puppet|
    puppet.facter = {
      "user_name" => ENV['USER']
    }
  end
end

This would pass the current logged in username through to puppet and then within your manifest files you could use the variable "$user_name" within your git commands to checkout the correct users repo and do any other related tasks.