aboutsummaryrefslogtreecommitdiff
path: root/roles/ssh_keys/tasks/main.yml.2016-09-22.04
blob: c9f33a9c6ee6b5394d2853376dd2400fb0df1eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
bgstack15