Skip to content

Commit

Permalink
don't create users depending on OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Van der Kussen committed Oct 2, 2018
1 parent 76ee1db commit 1645364
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion add-users-groups-authorized_keys-dot-files/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ retry_files_save_path = /tmp/
inventory=./hosts
host_key_checking=False
gathering = smart
stdout_callback=unixy
#stdout_callback=unixy
#stdout_callback=debug

[privilege_escalation]
Expand Down
19 changes: 19 additions & 0 deletions add-users-groups-authorized_keys-dot-files/group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ users:
csh_lines:
- line: "alias ls ls -lah"
state: present
- name: freebsd
state: present
keys:
- file: key2
state: present
csh_lines:
- line: "alias ls ls -lah"
state: present
- name: ubuntu
state: present
keys:
- file: key2
state: absent
bash_lines:
- line: "alias ls ls -lah"
state: present
ssh_config:
- line: "ServerAliveInterval: 10"
- line: "Compression no"
2 changes: 2 additions & 0 deletions add-users-groups-authorized_keys-dot-files/hosts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
10.106.116.157 ansible_user=root
10.106.116.139 ansible_user=root
#34.242.108.38 ssh_short_name=freebsd1 ansible_user=ec2-user ansible_python_interpreter=/usr/local/bin/python2.7
34.242.147.18 ansible_user=ubuntu
34.241.111.239 ansible_user=ec2-user ansible_python_interpreter=/usr/local/bin/python2.7
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
- name: Check if user has ~/.ssh/config
- name: Check if user has ~/.ssh/config | Debian/Ubuntu systems.
stat:
path: "/home/{{ item.name }}/.ssh/config"
with_items: "{{ users }}"
register: sshconfig
when: item.name != 'freebsd' and ansible_os_family == 'Debian'

- name: debug
debug: "{{ item.item.name }}"
with_items:
- "{{ sshconfig.results }}"

- name: Create ~/.ssh/config when absent
file:
Expand All @@ -13,10 +18,10 @@
group: "{{ item.item.name }}"
mode: 0600
state: touch
when: item.stat.exists == False and item.item.state == "present"
when: item.stat is defined and item.stat.exists == False and item.item.state == "present"
with_items:
- "{{ sshconfig.results }}"
no_log: True
#no_log: True


- name: CHECK VARS
Expand Down Expand Up @@ -51,5 +56,6 @@
with_items:
- "{{ users }}"
- skip_missing: true
when: item.ssh_config is defined and item.state == "present"
when: item.ssh_config is defined and item.state == "present" and item.name != 'freebsd' and ansible_os_family == 'Debian'


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

- name: Ensure .ssh folder is created
- name: Ensure .ssh folder is created | Debian/Ubuntu systems
file:
path: "/home/{{item.name}}/.ssh"
state: directory
Expand All @@ -8,16 +8,37 @@
group: "{{ item.name }}"
with_items:
- "{{ users }}"
when: item.state == "present"
when: item.state == "present" and item.name != 'freebsd' and ansible_os_family == 'Debian'


- name: Configure authorized_keys
- name: Configure authorized_keys | Debian/Ubuntu systems
authorized_key:
user: "{{ item.0.name }}"
key: "{{ lookup('file', 'keys/' + item.0.name + '/' + item.1.file + '.pub') }}"
state: "{{ item.1.state | default('present') }}"
with_subelements:
- "{{ users }}"
- keys
when: item.0.state is defined and item.0.state == "present"
when: item.0.state is defined and item.0.state == "present" and item.0.name != 'freebsd' and ansible_os_family == 'Debian'

- name: Ensure .ssh folder is created | FreeBSD systems
file:
path: "/home/{{item.name}}/.ssh"
state: directory
mode: 0700
owner: "{{ item.name }}"
group: "{{ item.name }}"
with_items:
- "{{ users }}"
when: item.state == "present" and item.name != 'ubuntu' and ansible_os_family == 'FreeBSD'


- name: Configure authorized_keys | FreeBSD systems
authorized_key:
user: "{{ item.0.name }}"
key: "{{ lookup('file', 'keys/' + item.0.name + '/' + item.1.file + '.pub') }}"
state: "{{ item.1.state | default('present') }}"
with_subelements:
- "{{ users }}"
- keys
when: item.0.state is defined and item.0.state == "present" and item.0.name != 'ubuntu' and ansible_os_family == 'FreeBSD'
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with_items: "{{ user_groups }}"


- name: Add/Remove user
- name: Add/Remove user(s) on Ubuntu systems
user:
name: "{{ item.name }}"
state: "{{ item.state | default('present') }}"
Expand All @@ -18,7 +18,20 @@
remove: yes
no_log: False
with_items: "{{ users }}"
when: item.name != 'freebsd' and ansible_os_family == 'Debian'

- name: Add/Remove user(s) on FreeBSD systems
user:
name: "{{ item.name }}"
state: "{{ item.state | default('present') }}"
password: "{{ item.password | default(omit) }}"
groups: "{{ item.groups | default(omit) }}"
uid: "{{ item.uid | default(omit) }}"
shell: "{{ item.shell | default(default_shell) }}"
remove: yes
no_log: False
with_items: "{{ users }}"
when: item.name != 'ubuntu' and ansible_os_family == 'FreeBSD'

- name: Configure bashrc lines
lineinfile:
Expand Down

0 comments on commit 1645364

Please sign in to comment.