Skip to content

Instantly share code, notes, and snippets.

@MacoTasu
Last active November 22, 2016 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacoTasu/94b7e97671f9c8aca7caeb04bc96ccac to your computer and use it in GitHub Desktop.
Save MacoTasu/94b7e97671f9c8aca7caeb04bc96ccac to your computer and use it in GitHub Desktop.
this is cookbook that in order to create sudores user by centos, depend on https://github.com/nownabe/itamae-plugin-resource-authorized_keys
# coding: utf-8
SUDO_GID=27
node.validate! do
{
sudoers: {
users: array_of({
name: string,
password: string,
github_name: string,
}),
},
}
end
for user_node in node['sudoers']['users'] do
user user_node['name'] do
# パスワードをSHA512にしたもの
password user_node['password']
shell "/bin/bash"
create_home true
action :create
end
execute "add wheel" do
only_if "id #{user_node['name']}"
not_if "getent group #{SUDO_GID} | grep #{user_node['name']}"
command "usermod #{user_node['name']} -aG #{SUDO_GID}"
end
authorized_keys "#{user_node['name']}" do
github "#{user_node['github_name']}"
end
end
@MacoTasu
Copy link
Author

example node json

{
    "role": "ap",
    "sudoers": {
        "users": [{
            "name": "macotasu",
            "password": "$6$xxxxxxx",
            "github_name": "macotasu"
        }]
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment