Commit 30f723a1 by arbabnazar

modified the user role

parent 37f7ae13
...@@ -35,6 +35,3 @@ user_rbash_links: ...@@ -35,6 +35,3 @@ user_rbash_links:
# will take precedence over the paramter # will take precedence over the paramter
user_info: [] user_info: []
user_debian_pkgs:
# Need this to get keys.
- curl
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
# # run manage.py commands # # run manage.py commands
# - name: automator # - name: automator
# type: restricted # type: restricted
# state: present
# # The sudoers file is optional. # # The sudoers file is optional.
# sudoers_template: '99-edxapp-manage-cmds.j2' # sudoers_template: '99-edxapp-manage-cmds.j2'
# authorized_keys: # authorized_keys:
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
# - name: frank # - name: frank
# github: true # github: true
# type: admin # type: admin
# state: present
# #
# # This user is a normal login user without sudo, with # # This user is a normal login user without sudo, with
# # a couple keys passed in as parameters # # a couple keys passed in as parameters
...@@ -69,90 +71,69 @@ ...@@ -69,90 +71,69 @@
# which can be passed in as a parameter to the role. # which can be passed in as a parameter to the role.
# #
- debug: var=user_info - debug:
var: user_info
- name: create the edxadmin group - name: create the edxadmin group
group: name=edxadmin state=present group:
name: edxadmin
- name: Install role-independent useful system packages
# do this before log dir setup; rsyslog package guarantees syslog user present
apt:
pkg: "{{ item }}"
install_recommends: yes
state: present state: present
update_cache: yes
with_items: user_debian_pkgs
# some AMIs (such as EMR master nodes) don't read the config files out of /etc/sudoers.d by default # some AMIs (such as EMR master nodes) don't read the config files out of /etc/sudoers.d by default
- name: ensure sudoers.d is read - name: ensure sudoers.d is read
lineinfile: > lineinfile:
dest=/etc/sudoers state=present dest: /etc/sudoers
regexp='^#includedir /etc/sudoers.d' line='#includedir /etc/sudoers.d' state: present
validate='visudo -cf %s' regexp: '^#includedir /etc/sudoers.d'
line: '#includedir /etc/sudoers.d'
validate: 'visudo -cf %s'
# give full sudo admin access to the edxadmin group # give full sudo admin access to the edxadmin group
- name: grant full sudo access to the edxadmin group - name: grant full sudo access to the edxadmin group
copy: > copy:
content="%edxadmin ALL=(ALL) NOPASSWD:ALL" content: "%edxadmin ALL=(ALL) NOPASSWD:ALL"
dest=/etc/sudoers.d/edxadmin owner=root group=root dest: /etc/sudoers.d/edxadmin
mode=0440 validate='visudo -cf %s' owner: root
group: root
mode: 0440
validate: 'visudo -cf %s'
- name: create the users - name: create the users
user: > user:
name={{ item.name }} name: "{{ item.name }}"
shell=/bin/bash shell: /bin/bash
state={{ item.state | default('present') }} state: "{{ item.state | default('present') }}"
with_items: user_info
- name: create .ssh directory
file: >
path=/home/{{ item.name }}/.ssh state=directory mode=0750
owner={{ item.name }}
when: item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
- name: assign admin role to admin users - name: assign admin role to admin users
user: > user:
name={{ item.name }} name: "{{ item.name }}"
groups=edxadmin groups: edxadmin
when: item.type is defined and item.type == 'admin' and item.get('state', 'present') == 'present' when: item.type is defined and item.type == 'admin' and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
# authorized_keys2 used here so that personal - name: get github key(s) and update the authorized_keys file
# keys can be copied to authorized_keys authorized_key:
# 2014/10/14 - using curl instead of get_url because user: "{{ item.name }}"
# get_url was failing due to certificate verification errors key: "https://github.com/{{ item.name }}.keys"
- name: get github key[s]
shell: >
curl https://github.com/{{ item.name }}.keys
sudo_user: "{{ item.name }}"
when: item.github is defined and item.get('state', 'present') == 'present' when: item.github is defined and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
register: github_keys
- name: update the authorized_keys file
template:
src="authorized_keys.j2"
dest="/home/{{ item.name }}/.ssh/authorized_keys"
owner="{{ item.name }}"
mode="600"
when: item.get('state', 'present') == 'present'
with_items: user_info
- name: create bashrc file for normal users - name: create bashrc file for normal users
template: > template:
src=default.bashrc.j2 src: default.bashrc.j2
dest=/home/{{ item.name }}/.bashrc mode=0640 dest: "/home/{{ item.name }}/.bashrc"
owner={{ item.name }} mode: 0640
owner: "{{ item.name }}"
when: not (item.type is defined and item.type == 'restricted') and item.get('state', 'present') == 'present' when: not (item.type is defined and item.type == 'restricted') and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
- name: create .profile for all users - name: create .profile for all users
template: > template:
src=default.profile.j2 src: default.profile.j2
dest=/home/{{ item.name }}/.profile mode=0640 dest: "/home/{{ item.name }}/.profile"
owner={{ item.name }} mode: 0640
owner: "{{ item.name }}"
when: item.get('state', 'present') == 'present' when: item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
...@@ -160,25 +141,29 @@ ...@@ -160,25 +141,29 @@
# All tasks below this line are for restricted users # All tasks below this line are for restricted users
- name: modify shell for restricted users - name: modify shell for restricted users
user: > user:
name={{ item.name }} name: "{{ item.name }}"
shell=/bin/rbash shell: /bin/rbash
when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present' when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
- name: create bashrc file for restricted users - name: create bashrc file for restricted users
template: > template:
src=restricted.bashrc.j2 src: restricted.bashrc.j2
dest=/home/{{ item.name }}/.bashrc mode=0640 dest: "/home/{{ item.name }}/.bashrc"
owner={{ item.name }} mode: 0640
owner: "{{ item.name }}"
when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present' when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
- name: create sudoers file from template - name: create sudoers file from template
template: > template:
dest=/etc/sudoers.d/99-restricted dest: /etc/sudoers.d/99-restricted
src=restricted.sudoers.conf.j2 owner="root" src: restricted.sudoers.conf.j2
group="root" mode=0440 validate='visudo -cf %s' owner: root
group: root
mode: 0440
validate: 'visudo -cf %s'
# Prevent restricted user from updating their PATH and # Prevent restricted user from updating their PATH and
# environment by ensuring root ownership # environment by ensuring root ownership
...@@ -189,9 +174,12 @@ ...@@ -189,9 +174,12 @@
with_items: user_info with_items: user_info
- name: create ~/bin directory - name: create ~/bin directory
file: > file:
path=/home/{{ item.name }}/bin state=directory mode=0750 path: "/home/{{ item.name }}/bin"
owner="root" group={{ item.name }} state: directory
mode: 0750
owner: root
group: "{{ item.name }}"
when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present' when: item.type is defined and item.type == 'restricted' and item.get('state', 'present') == 'present'
with_items: user_info with_items: user_info
......
# Keys from github
{% for github_key in github_keys.results -%}
{# None is lowercase in jinja... #}
{%- if github_key.changed -%}
{%- if github_key.item.name == item.name -%}
{{ github_key.stdout }}
{%- endif -%}
{%- endif -%}
{% endfor %}
{% if item.get('authorized_keys') %}
# Explicitly specified keys
{{ '\n'.join(item.authorized_keys) }}
{% endif %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment