From 5e8a7ac51e486044c8d14694e5f51173dd63f628 Mon Sep 17 00:00:00 2001 From: B Stack Date: Fri, 23 Sep 2016 10:27:15 -0400 Subject: Initial file upload --- roles/ssh_keys/main.yml | 8 ++++ roles/ssh_keys/tasks/main.yml | 63 +++++++++++++++++++++++++++++ roles/ssh_keys/tasks/main.yml.2016-09-22.01 | 26 ++++++++++++ roles/ssh_keys/tasks/main.yml.2016-09-22.02 | 28 +++++++++++++ roles/ssh_keys/tasks/main.yml.2016-09-22.03 | 40 ++++++++++++++++++ roles/ssh_keys/tasks/main.yml.2016-09-22.04 | 61 ++++++++++++++++++++++++++++ roles/ssh_keys/tasks/main.yml.2016-09-22.05 | 61 ++++++++++++++++++++++++++++ roles/ssh_keys/tests/test.yml | 13 ++++++ roles/ssh_keys/vars/AIX.yml | 2 + roles/ssh_keys/vars/default.yml | 2 + 10 files changed, 304 insertions(+) create mode 100644 roles/ssh_keys/main.yml create mode 100644 roles/ssh_keys/tasks/main.yml create mode 100644 roles/ssh_keys/tasks/main.yml.2016-09-22.01 create mode 100644 roles/ssh_keys/tasks/main.yml.2016-09-22.02 create mode 100644 roles/ssh_keys/tasks/main.yml.2016-09-22.03 create mode 100644 roles/ssh_keys/tasks/main.yml.2016-09-22.04 create mode 100644 roles/ssh_keys/tasks/main.yml.2016-09-22.05 create mode 100644 roles/ssh_keys/tests/test.yml create mode 100644 roles/ssh_keys/vars/AIX.yml create mode 100644 roles/ssh_keys/vars/default.yml (limited to 'roles/ssh_keys') diff --git a/roles/ssh_keys/main.yml b/roles/ssh_keys/main.yml new file mode 100644 index 0000000..9022768 --- /dev/null +++ b/roles/ssh_keys/main.yml @@ -0,0 +1,8 @@ +--- +- hosts: all + vars_files: + - vars/default.yml + tasks: + - include: tasks/main.yml + handlers: + - handlers/main.yml diff --git a/roles/ssh_keys/tasks/main.yml b/roles/ssh_keys/tasks/main.yml new file mode 100644 index 0000000..89d8d89 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml @@ -0,0 +1,63 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +#- shell: echo "{{ item | basename | regex_replace('\.pubkeys?$','') }}" +# with_fileglob: +# - '*.pubkey' +# - '*.pubkeys' +# register: users_to_check + +#- debug: var=ssh_key_strings +#- debug: var=ssh_key_files + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_strings }}' + register: "s" + when: ssh_key_strings is defined + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_files }}' + register: "r" + when: ssh_key_files is defined + +#- debug: msg='{{ item.stat.exists }}' +# with_flattened: +# - '{{ r.results }}' + +- name: ssh_keys deploy keys from files + template: + src: "roles/ssh_keys/files/{{ item.item.file }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + with_items: + - '{{ r.results }}' + when: + - item.stat.exists is defined + - '{{ item.stat.exists }}' + - r is defined + +- name: ssh_keys deploy keys from strings + lineinfile: + line: '{{ item.item.string }}' + regexp: "{{ item.item.string | regex_replace('^(.{40}).*$','\\1') }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + create: yes + state: present + with_items: + - '{{ s.results }}' + when: + - item.stat.exists is defined + - '{{ item.stat.exists }}' + - s is defined diff --git a/roles/ssh_keys/tasks/main.yml.2016-09-22.01 b/roles/ssh_keys/tasks/main.yml.2016-09-22.01 new file mode 100644 index 0000000..b9536c4 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml.2016-09-22.01 @@ -0,0 +1,26 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +- stat: path='{{ master_home_dir }}/{{ item | basename | regex_replace('\.pubkeys?$','') }}/.ssh' + register: files_stat + with_fileglob: + - '*.pubkey' + - '*.pubkeys' + +- debug: var='{{ item.stat.exists }}' + with_items: '{{ files_stat.results }}' + +- name: ssh_keys deploy keys + template: src='{{ item }}' dest='{{ master_home_dir }}/{{ item | basename | regex_replace('\.pubkeys?$','') }}/.ssh/authorized_keys' mode=0600 owner='{{ item | basename | regex_replace('\.pubkeys?$',"") }}' + with_fileglob: + - '*.pubkey' + - '*.pubkeys' + #when: item2.stat.exists + #with_items: '{{ files_stat.results }}' diff --git a/roles/ssh_keys/tasks/main.yml.2016-09-22.02 b/roles/ssh_keys/tasks/main.yml.2016-09-22.02 new file mode 100644 index 0000000..17f6d66 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml.2016-09-22.02 @@ -0,0 +1,28 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +- shell: echo "{{ item | basename | regex_replace('\.pubkeys?$','') }}" + with_fileglob: + - '*.pubkey' + - '*.pubkeys' + register: users_to_check + +- debug: msg="{{ item.stdout_lines }}" + with_items: + - '{{ users_to_check.results }}' + +#- debug: var='{{ item.stdout_lines }}' +# with_items: +# - '{{ users_to_check.items }}' + +#- name: ssh_keys deploy keys +# template: src='{{ item.stdout_lines }}.pubkey' dest='{{ master_home_dir }}/{{ item.stdout_lines }}/.ssh/authorized_keys' mode=0600 owner='{{ item.stdout_lines }}' +# with_items: +# - '{{ users_to_check.results }}' diff --git a/roles/ssh_keys/tasks/main.yml.2016-09-22.03 b/roles/ssh_keys/tasks/main.yml.2016-09-22.03 new file mode 100644 index 0000000..3729179 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml.2016-09-22.03 @@ -0,0 +1,40 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +#- shell: echo "{{ item | basename | regex_replace('\.pubkeys?$','') }}" +# with_fileglob: +# - '*.pubkey' +# - '*.pubkeys' +# register: users_to_check + +#- debug: var=ssh_key_strings +#- debug: var=ssh_key_files + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_files }}' + register: "r" + +#- debug: msg='{{ item.stat.exists }}' +# with_flattened: +# - '{{ r.results }}' + +- name: ssh_keys deploy keys from files + template: + src: "roles/ssh_keys/files/{{ item.item.file }}" + dest: '{{ master_home_dir}}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + with_items: + - '{{ r.results }}' + when: + - '{{ item.stat.exists }}' + +- name: ssh_keys deploy keys from diff --git a/roles/ssh_keys/tasks/main.yml.2016-09-22.04 b/roles/ssh_keys/tasks/main.yml.2016-09-22.04 new file mode 100644 index 0000000..c9f33a9 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml.2016-09-22.04 @@ -0,0 +1,61 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +#- shell: echo "{{ item | basename | regex_replace('\.pubkeys?$','') }}" +# with_fileglob: +# - '*.pubkey' +# - '*.pubkeys' +# register: users_to_check + +#- debug: var=ssh_key_strings +#- debug: var=ssh_key_files + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_strings }}' + register: "s" + when: ssh_key_strings is defined + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_files }}' + register: "r" + when: ssh_key_files is defined + +#- debug: msg='{{ item.stat.exists }}' +# with_flattened: +# - '{{ r.results }}' + +- name: ssh_keys deploy keys from files + template: + src: "roles/ssh_keys/files/{{ item.item.file }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + with_items: + - '{{ r.results }}' + when: + - '{{ item.stat.exists }}' + - r is defined + +- name: ssh_keys deploy keys from strings + lineinfile: + line: '{{ item.item.string }}' + regexp: "{{ item.item.string | regex_replace('^(.{20}).*$','\\1') }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + create: yes + state: present + with_items: + - '{{ s.results }}' + when: + - '{{ item.stat.exists }}' + - s is defined diff --git a/roles/ssh_keys/tasks/main.yml.2016-09-22.05 b/roles/ssh_keys/tasks/main.yml.2016-09-22.05 new file mode 100644 index 0000000..6d82cd0 --- /dev/null +++ b/roles/ssh_keys/tasks/main.yml.2016-09-22.05 @@ -0,0 +1,61 @@ +--- +- name: ssh_keys get vars + include_vars: default.yml + +- name: ssh_keys get OS vars + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - default.yml + +#- shell: echo "{{ item | basename | regex_replace('\.pubkeys?$','') }}" +# with_fileglob: +# - '*.pubkey' +# - '*.pubkeys' +# register: users_to_check + +#- debug: var=ssh_key_strings +#- debug: var=ssh_key_files + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_strings }}' + register: "s" + when: ssh_key_strings is defined + +- stat: path='{{ master_home_dir}}/{{ item.user }}/.ssh' + with_items: + - '{{ ssh_key_files }}' + register: "r" + when: ssh_key_files is defined + +#- debug: msg='{{ item.stat.exists }}' +# with_flattened: +# - '{{ r.results }}' + +- name: ssh_keys deploy keys from files + template: + src: "roles/ssh_keys/files/{{ item.item.file }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + with_items: + - '{{ r.results }}' + when: + - '{{ item.stat.exists }}' + - r is defined + +- name: ssh_keys deploy keys from strings + lineinfile: + line: '{{ item.item.string }}' + regexp: "{{ item.item.string | regex_replace('^(.{40}).*$','\\1') }}" + dest: '{{ master_home_dir }}/{{ item.item.user }}/.ssh/authorized_keys' + mode: 0600 + owner: '{{ item.item.user }}' + create: yes + state: present + with_items: + - '{{ s.results }}' + when: + - '{{ item.stat.exists }}' + - s is defined diff --git a/roles/ssh_keys/tests/test.yml b/roles/ssh_keys/tests/test.yml new file mode 100644 index 0000000..3397909 --- /dev/null +++ b/roles/ssh_keys/tests/test.yml @@ -0,0 +1,13 @@ +--- +- name: Test ssh_keys + hosts: test + remote_user: root + roles: + - ssh_keys + vars: +# ssh_key_strings: +# - { user: 'jdoe', string: 'a public key here' } +# - { user: 'alice', string: 'public key here' } +# ssh_key_files: +# - { user: 'jdoe', file: '../../../company/pubkeys/jdoe.pubkeys' } +# - { user: 'alice', file: '../../../company/pubkeys/alice.pubkey' } diff --git a/roles/ssh_keys/vars/AIX.yml b/roles/ssh_keys/vars/AIX.yml new file mode 100644 index 0000000..22f4611 --- /dev/null +++ b/roles/ssh_keys/vars/AIX.yml @@ -0,0 +1,2 @@ +--- +master_home_dir: /home/users diff --git a/roles/ssh_keys/vars/default.yml b/roles/ssh_keys/vars/default.yml new file mode 100644 index 0000000..f9662af --- /dev/null +++ b/roles/ssh_keys/vars/default.yml @@ -0,0 +1,2 @@ +--- +master_home_dir: /home -- cgit