Skip to content

Commit

Permalink
Merge pull request #6 from route1337/zsh
Browse files Browse the repository at this point in the history
Starting the move to zsh
  • Loading branch information
ahrenstein authored Jul 17, 2020
2 parents 554cfaf + 940c34e commit 08fe902
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Ansible Role - Linux Users: Changelog
=====================================
A list of all the changes made to this repo and the role it contains

Version 1.2.2
-------------

1. Install zsh if it's missing
2. Users now use zsh as their default shell

Version 1.2.1
-------------

Expand Down
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# Manage user accounts and sudo privileges across Linux servers

- name: Set distribution specific variables
include_vars: '{{ item }}'
with_first_found:
- '{{ ansible_distribution }}.yml'
- import_tasks: prereqs.yml
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'CentOS'
- import_tasks: root.yml
Expand Down
17 changes: 17 additions & 0 deletions tasks/prereqs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@

# Configure the prerequisites for user management

- name: (Ubuntu) Refresh apt cache
apt:
update_cache: yes
when: ansible_distribution == "Ubuntu"

- name: (Ubuntu) Install the zsh package
apt:
name: zsh
state: present
when: ansible_distribution == "Ubuntu"

- name: (CentOS) Install the zsh package
yum:
name: zsh
state: present
when: ansible_distribution == "CentOS"

- name: Create an admin group for password-less sudo options
group:
gid: 1337
Expand Down
1 change: 1 addition & 0 deletions tasks/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
user:
name: root
password: '{{ linux_users.root_password }}'
shell: '{{ zsh_path }}'
update_password: always

- name: Configure root's SSH keys
Expand Down
2 changes: 1 addition & 1 deletion tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- name: Add/update all specified users
user:
name: '{{ item.username }}'
shell: '/bin/bash'
shell: '{{ zsh_path }}'
comment: '{{ item.comment }}'
create_home: yes
group: '{{ item.group }}'
Expand Down
5 changes: 5 additions & 0 deletions tests/smoke/repo-role/no-user-management/prereqs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

if ['ubuntu', 'centos'].include?(os[:name])

# Verify zsh is installed
describe package('zsh') do
it { should be_installed }
end

# Verify the sysadmins group exists
describe group('sysadmins') do
it { should exist }
Expand Down
5 changes: 5 additions & 0 deletions tests/smoke/repo-role/standard/prereqs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

if ['ubuntu', 'centos'].include?(os[:name])

# Verify zsh is installed
describe package('zsh') do
it { should be_installed }
end

# Verify the sysadmins group exists
describe group('sysadmins') do
it { should exist }
Expand Down
16 changes: 13 additions & 3 deletions tests/smoke/repo-role/standard/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

# Test the creation and updating of users

if os[:name] == 'ubuntu'
zsh_path = '/usr/bin/zsh'

elsif os[:name] == 'centos'
zsh_path = '/bin/zsh'

else
# Do nothing
end

if ['ubuntu', 'centos'].include?(os[:name])

# Verify the sample user "pgibbons" was created
Expand All @@ -19,7 +29,7 @@
its('gid') { should eq 8737 }
its('group') { should eq 'sysusers' }
its('home') { should eq '/home/pgibbons' }
its('shell') { should eq '/bin/bash' }
its('shell') { should eq "#{zsh_path}" }
end

# Verify the sample user "pgibbons" has the correct SSH key(s)
Expand All @@ -37,7 +47,7 @@
its('gid') { should eq 1337 }
its('group') { should eq 'sysadmins' }
its('home') { should eq '/home/ahrenstein' }
its('shell') { should eq '/bin/bash' }
its('shell') { should eq "#{zsh_path}" }
end

# Verify the sample user "ahrenstein" has the correct SSH key(s)
Expand All @@ -55,7 +65,7 @@
its('gid') { should eq 7782 }
its('group') { should eq 'svcaccounts' }
its('home') { should eq '/home/svc-ghactions' }
its('shell') { should eq '/bin/bash' }
its('shell') { should eq "#{zsh_path}" }
end

# Verify the sample user "svc-ghactions" has the correct SSH key(s)
Expand Down
14 changes: 14 additions & 0 deletions vars/CentOS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Project:: Ansible Role - Linux Users
#
# Copyright 2020, Route 1337, LLC, All Rights Reserved.
#
# Maintainers:
# - Matthew Ahrenstein: [email protected]
#
# See LICENSE
#

# Variables specific to CentOS

zsh_path: "/bin/zsh"
14 changes: 14 additions & 0 deletions vars/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Project:: Ansible Role - Linux Users
#
# Copyright 2020, Route 1337, LLC, All Rights Reserved.
#
# Maintainers:
# - Matthew Ahrenstein: [email protected]
#
# See LICENSE
#

# Variables specific to Ubuntu

zsh_path: "/usr/bin/zsh"

0 comments on commit 08fe902

Please sign in to comment.