Changes between Version 8 and Version 9 of ChefNotes


Ignore:
Timestamp:
May 19, 2014 9:24:20 AM (10 years ago)
Author:
Geoff Lawler
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ChefNotes

    v8 v9  
    8787Success. accounts::default recipe is
    8888{{{
     89require 'rubygems'
     90require 'mysql2'
     91
     92# All these hardcoded values need to be imported somehow.
     93dbhost = "myboss"
     94dbuser = "mysql"
     95dbname = "tbdb"
     96pid = "Deter"
     97
     98Chef::Log.info("Connecting to db #{dbname} on #{dbhost} as #{dbuser}")
     99client = Mysql2::Client.new(:host => dbhost, :username => dbuser, :database => dbname)
     100Chef::Log.info("Connected. Querying for appropriate user accounts.")
     101
     102# ugly SQL stolen from tmcd.c
     103# to do this right, we need to analyise all the user cases from tmcd.c for
     104# account creation and add them here (or the ones we want to support anyway.
     105stmt = "select distinct "
     106stmt << "  u.uid,u.usr_pswd,u.unix_uid,u.usr_name, "
     107stmt << "  p.trust,g.pid,g.gid,g.unix_gid,u.admin, "
     108stmt << "  u.emulab_pubkey,u.home_pubkey, "
     109stmt << "  UNIX_TIMESTAMP(u.usr_modified), "
     110stmt << "  u.usr_email,u.usr_shell, "
     111stmt << "  u.widearearoot,u.wideareajailroot, "
     112stmt << "  u.usr_w_pswd,u.uid_idx "
     113stmt << "from group_membership as p "
     114stmt << "join users as u on p.uid_idx=u.uid_idx "
     115stmt << "join groups as g on "
     116stmt << "     p.pid=g.pid and p.gid=g.gid "
     117stmt << "where ((p.pid='#{pid}')) and p.trust!='none' "
     118stmt << "      and u.status='active' "
     119stmt << "      and u.webonly=0 "
     120stmt << "      and g.unix_gid is not NULL "
     121stmt << "order by u.uid"
     122
     123results = client.query(stmt)
     124
     125results.each do | row |
     126    user row['uid'] do
     127        Chef::Log.info("Creating account for #{row['uid']} (#{row['usr_name']})")
     128        supports :manage_home => false   # do not create home dir, it'll be mounted from ops
     129        supports :non_unique => false    # so not allow multiple account with like uids.
     130        password row['usr_pswd']
     131        shell "/bin/#{row['usr_shell']}"  # TODO fix path here what if shell is not in /bin?
     132        home "/users/#{row['uid']}"
     133        uid row['unix_uid']
     134        gid row['unix_gid']
     135        username row['uid']
     136        if row['admin']
     137            Chef::Log.info("#{row['uid']} is an admin account.")
     138            system true
     139        end
     140        action :create
     141    end
     142end
     143
    89144}}}
    90145