Skip to content

Instantly share code, notes, and snippets.

@MacoTasu MacoTasu/sudoers.rb

Last active Nov 22, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

MacoTasu commented Nov 22, 2016

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
You can’t perform that action at this time.