From 164536462ab85b9165de32992a6f0ed24c242548 Mon Sep 17 00:00:00 2001 From: Vincent Van der Kussen Date: Tue, 2 Oct 2018 19:38:23 +0200 Subject: [PATCH 01/14] don't create users depending on OS --- .../ansible.cfg | 2 +- .../group_vars/all | 19 ++++++++++++ .../hosts | 2 ++ .../roles/ssh-config/tasks/main.yml | 14 ++++++--- .../roles/users/files/keys/freebsd/key2.pub | 1 + .../roles/users/files/keys/ubuntu/key2.pub | 1 + .../roles/users/tasks/ssh_config.yml | 29 ++++++++++++++++--- .../roles/users/tasks/users.yml | 15 +++++++++- 8 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub create mode 100644 add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub diff --git a/add-users-groups-authorized_keys-dot-files/ansible.cfg b/add-users-groups-authorized_keys-dot-files/ansible.cfg index 6efa305..f4923f1 100644 --- a/add-users-groups-authorized_keys-dot-files/ansible.cfg +++ b/add-users-groups-authorized_keys-dot-files/ansible.cfg @@ -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] diff --git a/add-users-groups-authorized_keys-dot-files/group_vars/all b/add-users-groups-authorized_keys-dot-files/group_vars/all index be5a4aa..a345002 100644 --- a/add-users-groups-authorized_keys-dot-files/group_vars/all +++ b/add-users-groups-authorized_keys-dot-files/group_vars/all @@ -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" diff --git a/add-users-groups-authorized_keys-dot-files/hosts b/add-users-groups-authorized_keys-dot-files/hosts index a0967ee..9eb28db 100644 --- a/add-users-groups-authorized_keys-dot-files/hosts +++ b/add-users-groups-authorized_keys-dot-files/hosts @@ -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 diff --git a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml index 2b22aea..7c12f4d 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml @@ -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: @@ -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 @@ -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' + diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub new file mode 100644 index 0000000..88ca4dd --- /dev/null +++ b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub new file mode 100644 index 0000000..88ca4dd --- /dev/null +++ b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml index 52b1c81..2e40bae 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml @@ -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 @@ -8,10 +8,10 @@ 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') }}" @@ -19,5 +19,26 @@ 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' diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml index aa4eb1f..22a4a90 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml @@ -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') }}" @@ -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: -- 2.44.2 From 17d3f699a0834634455737a56c83306bf491c1a4 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 15:10:30 -0700 Subject: [PATCH 02/14] leaving it --- .../ansible.cfg | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 add-users-groups-authorized_keys-dot-files/ansible.cfg diff --git a/add-users-groups-authorized_keys-dot-files/ansible.cfg b/add-users-groups-authorized_keys-dot-files/ansible.cfg deleted file mode 100644 index f4923f1..0000000 --- a/add-users-groups-authorized_keys-dot-files/ansible.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[ssh_connection] - -[defaults] -retry_files_enabled = False -retry_files_save_path = /tmp/ -inventory=./hosts -host_key_checking=False -gathering = smart -#stdout_callback=unixy -#stdout_callback=debug - -[privilege_escalation] -become=True -become_method=sudo -become_user=root -#become_ask_pass=False - -- 2.44.2 From 24431d9a8faf9799e880ad0bf569f826f2c04e1c Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 15:28:35 -0700 Subject: [PATCH 03/14] Revert "leaving it" This reverts commit 17d3f699a0834634455737a56c83306bf491c1a4. --- .../ansible.cfg | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 add-users-groups-authorized_keys-dot-files/ansible.cfg diff --git a/add-users-groups-authorized_keys-dot-files/ansible.cfg b/add-users-groups-authorized_keys-dot-files/ansible.cfg new file mode 100644 index 0000000..f4923f1 --- /dev/null +++ b/add-users-groups-authorized_keys-dot-files/ansible.cfg @@ -0,0 +1,17 @@ +[ssh_connection] + +[defaults] +retry_files_enabled = False +retry_files_save_path = /tmp/ +inventory=./hosts +host_key_checking=False +gathering = smart +#stdout_callback=unixy +#stdout_callback=debug + +[privilege_escalation] +become=True +become_method=sudo +become_user=root +#become_ask_pass=False + -- 2.44.2 From 84fd00c37c73f6d0eb7870b0b0079d79db2108bc Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:18:39 -0700 Subject: [PATCH 04/14] Update hosts --- add-users-groups-authorized_keys-dot-files/hosts | 2 -- 1 file changed, 2 deletions(-) diff --git a/add-users-groups-authorized_keys-dot-files/hosts b/add-users-groups-authorized_keys-dot-files/hosts index 9eb28db..a0967ee 100644 --- a/add-users-groups-authorized_keys-dot-files/hosts +++ b/add-users-groups-authorized_keys-dot-files/hosts @@ -1,5 +1,3 @@ 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 -- 2.44.2 From 81ad87f241061782783924403d6f8cb4918eedb0 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:18:51 -0700 Subject: [PATCH 05/14] Update ansible.cfg --- add-users-groups-authorized_keys-dot-files/ansible.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-users-groups-authorized_keys-dot-files/ansible.cfg b/add-users-groups-authorized_keys-dot-files/ansible.cfg index f4923f1..6efa305 100644 --- a/add-users-groups-authorized_keys-dot-files/ansible.cfg +++ b/add-users-groups-authorized_keys-dot-files/ansible.cfg @@ -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] -- 2.44.2 From 81d6d4e8ff866bcbf94ddbc2857653bee3290688 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:29:28 -0700 Subject: [PATCH 06/14] fixing incorrect username, not what was requested https://github.com/stationgroup/ansible-experiments/issues/13#issue-361852126 This is still missing `vagrant`. --- .../roles/users/tasks/users.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml index 22a4a90..bec7871 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/users.yml @@ -18,7 +18,7 @@ remove: yes no_log: False with_items: "{{ users }}" - when: item.name != 'freebsd' and ansible_os_family == 'Debian' + when: item.name != 'ec2-user' and ansible_os_family == 'Debian' - name: Add/Remove user(s) on FreeBSD systems user: -- 2.44.2 From 5d4c7f9f55a08dd6dcf811599bea3f159975b4cb Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:31:22 -0700 Subject: [PATCH 07/14] fixing incorrect username https://github.com/stationgroup/ansible-experiments/issues/13#issue-361852126 --- .../roles/ssh-config/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml index 7c12f4d..0625e2b 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml @@ -4,7 +4,7 @@ path: "/home/{{ item.name }}/.ssh/config" with_items: "{{ users }}" register: sshconfig - when: item.name != 'freebsd' and ansible_os_family == 'Debian' + when: item.name != 'ec2-user' and ansible_os_family == 'Debian' - name: debug debug: "{{ item.item.name }}" @@ -56,6 +56,6 @@ with_items: - "{{ users }}" - skip_missing: true - when: item.ssh_config is defined and item.state == "present" and item.name != 'freebsd' and ansible_os_family == 'Debian' + when: item.ssh_config is defined and item.state == "present" and item.name != 'ec2-user' and ansible_os_family == 'Debian' -- 2.44.2 From ec611b20302b13bd80631d799525c313a9282949 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:32:45 -0700 Subject: [PATCH 08/14] fixing incorrect user name --- .../roles/users/tasks/ssh_config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml index 2e40bae..7f56fc7 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/users/tasks/ssh_config.yml @@ -8,7 +8,7 @@ group: "{{ item.name }}" with_items: - "{{ users }}" - when: item.state == "present" and item.name != 'freebsd' and ansible_os_family == 'Debian' + when: item.state == "present" and item.name != 'ec2-user' and ansible_os_family == 'Debian' - name: Configure authorized_keys | Debian/Ubuntu systems @@ -19,7 +19,7 @@ with_subelements: - "{{ users }}" - keys - when: item.0.state is defined and item.0.state == "present" and item.0.name != 'freebsd' and ansible_os_family == 'Debian' + when: item.0.state is defined and item.0.state == "present" and item.0.name != 'ec2-user' and ansible_os_family == 'Debian' - name: Ensure .ssh folder is created | FreeBSD systems file: -- 2.44.2 From 64ce20d9b62f00f939ca268a213066bffaba6a87 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:37:08 -0700 Subject: [PATCH 09/14] Update all --- .../group_vars/all | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/add-users-groups-authorized_keys-dot-files/group_vars/all b/add-users-groups-authorized_keys-dot-files/group_vars/all index a345002..be5a4aa 100644 --- a/add-users-groups-authorized_keys-dot-files/group_vars/all +++ b/add-users-groups-authorized_keys-dot-files/group_vars/all @@ -45,22 +45,3 @@ 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.44.2 From 881f3b4e1ffb2e61d9164528a217fa6926bca1ad Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:42:13 -0700 Subject: [PATCH 10/14] Update main.yml --- .../roles/ssh-config/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml index 0625e2b..d36f0c7 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml @@ -21,7 +21,7 @@ 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 -- 2.44.2 From acc7a2a2a6678fea6a80f150cfbdcd0e89eed36f Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:43:19 -0700 Subject: [PATCH 11/14] Delete key2.pub --- .../roles/users/files/keys/freebsd/key2.pub | 1 - 1 file changed, 1 deletion(-) delete mode 100644 add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub deleted file mode 100644 index 88ca4dd..0000000 --- a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/freebsd/key2.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd -- 2.44.2 From e0f1ab4984c39ad0987ab495512a205f4b75a2f1 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Mon, 8 Oct 2018 17:43:26 -0700 Subject: [PATCH 12/14] Delete key2.pub --- .../roles/users/files/keys/ubuntu/key2.pub | 1 - 1 file changed, 1 deletion(-) delete mode 100644 add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub diff --git a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub b/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub deleted file mode 100644 index 88ca4dd..0000000 --- a/add-users-groups-authorized_keys-dot-files/roles/users/files/keys/ubuntu/key2.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMfztaQoo3Alf4Ie4ZrSEkhojOcKl8VRdoRiYb/7FL3IS/5IcSKcan/MGJlRht3ibwJBx9/CY8wZivHgNKCqtbZWGepfOtgWOqI4ROo4sELmRgV8PZUACjCSfaOkOdvCJEjhw3n+aI5jmK9IUA+mwdXkZj/NckNDZAQ+FRqwR6sX7svM4TF/zEI70JvO3xnDgCuC2PgiztVFfMqbWl33NgkG3kWkJ+JarF2pNsxO/+82s/hoC4P+dpZD1PHhJC7OxUiAHe5nwF7heQh9DUBQxJBhitn7C3XqlxEf7Kx3/kO9CUJVDaxS84UUnfUPc0u1iYpE+5ypqkDSyj3yQNpwXd -- 2.44.2 From b4cd66f75d52c514975cb5bebe33ba8b5808a597 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Sat, 20 Oct 2018 18:16:48 -0700 Subject: [PATCH 13/14] freebsd fix --- .../roles/ssh-config/tasks/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml index d36f0c7..2b2c8c2 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml @@ -5,6 +5,13 @@ with_items: "{{ users }}" register: sshconfig when: item.name != 'ec2-user' and ansible_os_family == 'Debian' + +- name: Check if user has ~/.ssh/config | FreeBSD systems. + stat: + path: "/home/{{ item.name }}/.ssh/config" + with_items: "{{ users }}" + register: sshconfig + when: item.name != 'ubuntu' and ansible_os_family == 'FreeBSD' - name: debug debug: "{{ item.item.name }}" -- 2.44.2 From 870157577912473838b9db07e4652656b4558a97 Mon Sep 17 00:00:00 2001 From: Bryan Black Date: Sat, 20 Oct 2018 18:18:32 -0700 Subject: [PATCH 14/14] freebsd fix --- .../roles/ssh-config/tasks/main.yml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml index 2b2c8c2..dc66fc8 100644 --- a/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml +++ b/add-users-groups-authorized_keys-dot-files/roles/ssh-config/tasks/main.yml @@ -65,4 +65,27 @@ - skip_missing: true when: item.ssh_config is defined and item.state == "present" and item.name != 'ec2-user' and ansible_os_family == 'Debian' - +- name: Configure ~/.ssh/config FreeBSD + blockinfile: + #path: "/home/{{ item.0.name }}/.ssh/config" + path: "/home/{{ item.name }}/.ssh/config" + #owner: "{{ item.0.name }}" + owner: "{{ item.name }}" + #group: "{{ item.0.name }}" + group: "{{ item.name }}" + mode: 0600 + marker: "# {mark} ANSIBLE MANAGED BLOCK" + content: | + {% for host in groups['all'] -%} + Host {{ hostvars[host]['ansible_hostname'] }} + Hostname {{ hostvars[host]['inventory_hostname'] }} + RemoteForward /home/{{ item.name }}/.gnupg/S.gpg-agent $HOME/.gnupg/S.gpg-agent + RemoteForward /home/{{ item.name }}/.gnupg/S.gpg-agent.ssh $HOME/.gnupg/S.gpg-agent.ssh + {% for item in item.ssh_config %} + {{ item.line }} + {% endfor %} + {% endfor %} + with_items: + - "{{ users }}" + - skip_missing: true + when: item.ssh_config is defined and item.state == "present" and item.name != 'ubuntu' and ansible_os_family == 'FreeBSD' -- 2.44.2