initial commit

This commit is contained in:
Ludovic Cartier 2024-11-08 16:14:46 +01:00
parent 79cc857a46
commit c7849945c3
5 changed files with 97 additions and 0 deletions

10
files/bash_completion Normal file
View File

@ -0,0 +1,10 @@
function _connect() {
COMPREPLY=()
local currentWord=${COMP_WORDS[COMP_CWORD]}
local completeHosts=$(cat /etc/passwd|grep "/var/www/sites"|cut -d ':' -f 1)
COMPREPLY=($(compgen -W "$completeHosts" -- "$currentWord"))
return 0
}
complete -F _connect groot

41
files/groot Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
function _help() {
echo "\
.^. . _
/: ||\`\/ \~ ,
, [ & / \ y'
{v': \`\ / \`&~-,
'y. ' |\` . ' /
\ ' . , y
v . ' v
V .~. .~. V
: ( 0) ( 0) :
i \`'\` \`'\` j
i __ ,j
\`%\`~....~'&
<~o' / \\/\` \-s,
o.~'. )( r .o ,.
o', %\`\`\\/\`\`& : 'bF
d', ,ri.~~-~.ri , +h
\`oso' d\`~..~\`b 'sos\`
d\`+ II +\`b
i_:_yi_;_y I am groot! (C)"
echo
echo "No argument given !"
echo "Usage: groot <TAB>" >&2
echo
exit 1
}
function _connect() {
sudo su - $1 -s /bin/bash
}
if [ -z "$1" ]; then
_help
else
echo -e "\n\033[1;35mEntering $1 environment...\033[00m\n"
_connect $1
fi

9
meta/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
galaxy_info:
author: Ludovic Cartier
description: Very simple impersonate wrapper
company: brainsys
license: GPLv3
min_ansible_version: 2.8
issue_tracker_url: https://git.brainsys.io/ansible-roles/groot/issues
github_branch: main

28
tasks/main.yml Normal file
View File

@ -0,0 +1,28 @@
---
- name: groot | copy bash-completion
copy:
src: bash_completion
dest: /etc/bash_completion.d/groot
owner: root
group: root
mode: 0644
tags: ['groot']
- name: groot | copy script
copy:
src: groot
dest: /usr/local/bin/groot
owner: root
group: root
mode: 0755
tags: ['groot']
- name: groot | create sudo priv
template:
src: sudoers.j2
dest: /etc/sudoers.d/groot
owner: root
group: root
mode: 0440
validate: "/usr/sbin/visudo -cf %s"
with_dict: "{{ groot }}"

9
templates/sudoers.j2 Normal file
View File

@ -0,0 +1,9 @@
# {{ ansible_managed }}
{% for user in groot %}
Defaults:{{ user }} !requiretty
{% for command in item.value -%}
{{ user }} ALL=(ALL:ALL) NOPASSWD: {{ command }}
{% endfor -%}
{% endfor %}