diff --git a/files/bash_completion b/files/bash_completion new file mode 100644 index 0000000..52e3b46 --- /dev/null +++ b/files/bash_completion @@ -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 diff --git a/files/groot b/files/groot new file mode 100644 index 0000000..a2410e4 --- /dev/null +++ b/files/groot @@ -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 " >&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 + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..1438ed2 --- /dev/null +++ b/meta/main.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..f52b627 --- /dev/null +++ b/tasks/main.yml @@ -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 }}" diff --git a/templates/sudoers.j2 b/templates/sudoers.j2 new file mode 100644 index 0000000..09c67a6 --- /dev/null +++ b/templates/sudoers.j2 @@ -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 %}