Skip to content

Instantly share code, notes, and snippets.

@goldeneggg
Last active December 15, 2015 08:29
Show Gist options
  • Save goldeneggg/5230975 to your computer and use it in GitHub Desktop.
Save goldeneggg/5230975 to your computer and use it in GitHub Desktop.
Chef : userを追加する

"user" resourceを使う

$ cd <chef-repo dir>/cookbooks
$ knife cookbook create user_add -o ./
$ cd user_add
$ vi attributes/user_add.rb
default['user'] = "hoge"
$ vi recipes/default.rb
user node['user'] do
    home "/home/#{node['user']}"
    password "phoge"
    shell "/bin/bash"
end
$ cd ../..
$ vi nodes/<server>.json
{
    "run_list":[
        "recipe[user_add]" # ★
    ]
}
$ knife solo cook [email protected]

[vagrant@vmchef1 ~]$ sudo cat /etc/passwd | grep hoge
hoge:x:501:502::/home/hoge:/bin/bash  ★OK
[vagrant@vmchef1 ~]$ sudo su - hoge
[hoge@vmchef1 ~]$  ★OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment