don't create users depending on OS
This commit is contained in:
parent
76ee1db759
commit
164536462a
|
@ -6,7 +6,7 @@ retry_files_save_path = /tmp/
|
||||||
inventory=./hosts
|
inventory=./hosts
|
||||||
host_key_checking=False
|
host_key_checking=False
|
||||||
gathering = smart
|
gathering = smart
|
||||||
stdout_callback=unixy
|
#stdout_callback=unixy
|
||||||
#stdout_callback=debug
|
#stdout_callback=debug
|
||||||
|
|
||||||
[privilege_escalation]
|
[privilege_escalation]
|
||||||
|
|
|
@ -45,3 +45,22 @@ users:
|
||||||
csh_lines:
|
csh_lines:
|
||||||
- line: "alias ls ls -lah"
|
- line: "alias ls ls -lah"
|
||||||
state: present
|
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"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
10.106.116.157 ansible_user=root
|
10.106.116.157 ansible_user=root
|
||||||
10.106.116.139 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.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
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
---
|
---
|
||||||
- name: Check if user has ~/.ssh/config
|
- name: Check if user has ~/.ssh/config | Debian/Ubuntu systems.
|
||||||
stat:
|
stat:
|
||||||
path: "/home/{{ item.name }}/.ssh/config"
|
path: "/home/{{ item.name }}/.ssh/config"
|
||||||
with_items: "{{ users }}"
|
with_items: "{{ users }}"
|
||||||
register: sshconfig
|
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
|
- name: Create ~/.ssh/config when absent
|
||||||
file:
|
file:
|
||||||
|
@ -13,10 +18,10 @@
|
||||||
group: "{{ item.item.name }}"
|
group: "{{ item.item.name }}"
|
||||||
mode: 0600
|
mode: 0600
|
||||||
state: touch
|
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:
|
with_items:
|
||||||
- "{{ sshconfig.results }}"
|
- "{{ sshconfig.results }}"
|
||||||
no_log: True
|
#no_log: True
|
||||||
|
|
||||||
|
|
||||||
- name: CHECK VARS
|
- name: CHECK VARS
|
||||||
|
@ -51,5 +56,6 @@
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ users }}"
|
- "{{ users }}"
|
||||||
- skip_missing: true
|
- 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'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd
|
|
@ -0,0 +1 @@
|
||||||
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
- name: Ensure .ssh folder is created
|
- name: Ensure .ssh folder is created | Debian/Ubuntu systems
|
||||||
file:
|
file:
|
||||||
path: "/home/{{item.name}}/.ssh"
|
path: "/home/{{item.name}}/.ssh"
|
||||||
state: directory
|
state: directory
|
||||||
|
@ -8,10 +8,10 @@
|
||||||
group: "{{ item.name }}"
|
group: "{{ item.name }}"
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ users }}"
|
- "{{ 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:
|
authorized_key:
|
||||||
user: "{{ item.0.name }}"
|
user: "{{ item.0.name }}"
|
||||||
key: "{{ lookup('file', 'keys/' + item.0.name + '/' + item.1.file + '.pub') }}"
|
key: "{{ lookup('file', 'keys/' + item.0.name + '/' + item.1.file + '.pub') }}"
|
||||||
|
@ -19,5 +19,26 @@
|
||||||
with_subelements:
|
with_subelements:
|
||||||
- "{{ users }}"
|
- "{{ users }}"
|
||||||
- keys
|
- 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'
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
with_items: "{{ user_groups }}"
|
with_items: "{{ user_groups }}"
|
||||||
|
|
||||||
|
|
||||||
- name: Add/Remove user
|
- name: Add/Remove user(s) on Ubuntu systems
|
||||||
user:
|
user:
|
||||||
name: "{{ item.name }}"
|
name: "{{ item.name }}"
|
||||||
state: "{{ item.state | default('present') }}"
|
state: "{{ item.state | default('present') }}"
|
||||||
|
@ -18,7 +18,20 @@
|
||||||
remove: yes
|
remove: yes
|
||||||
no_log: False
|
no_log: False
|
||||||
with_items: "{{ users }}"
|
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
|
- name: Configure bashrc lines
|
||||||
lineinfile:
|
lineinfile:
|
||||||
|
|
Loading…
Reference in a new issue