Skip to content

Commit

Permalink
updated variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
steenzout committed Sep 22, 2016
1 parent 33e7376 commit b7efd3e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
- **debug**: flag to run debug tasks.
- **ssh_config**: `ssh_config` file configuration.
- **ssh_config_path**: path to `ssh_config` file.
- **ssh_known_hosts_global**: list of hostname that need to be on the global `ssh_known_hosts` file.
- **ssh_known_hosts_global_scan**: list of hostname that after a `keyscan` are added to the global `ssh_known_hosts` file.
- **ssh_known_hosts_global_path**: path to the `ssh_known_hosts` file.
- **ssh_known_hosts_user**: list of hostname that need to be on a user's `known_hosts` file.
- **ssh_known_hosts_user_scan**: list of hostnames that after a `keyscan` are added to the user's `known_hosts` file.


## Dependencies
Expand All @@ -48,9 +48,9 @@ None.

- hosts: servers
vars:
ssh_known_hosts_global:
ssh_known_hosts_global_scan:
- github.com
ssh_known_hosts_user:
ssh_known_hosts_user_scan:
- user: vagrant
hosts:
- bitbucket.com
Expand Down
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#

ssh_config_path: /etc/ssh/ssh_config
ssh_known_hosts_global: []
ssh_known_hosts_global_scan: []
ssh_known_hosts_global_path: /etc/ssh/ssh_known_hosts
ssh_known_hosts_user: {}
ssh_known_hosts_user_scan: {}
4 changes: 2 additions & 2 deletions tasks/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
with_items:
- ssh_config
- ssh_config_path
- ssh_known_hosts_global
- ssh_known_hosts_global_scan
- ssh_known_hosts_global_path
- ssh_known_hosts_user
- ssh_known_hosts_user_scan
10 changes: 5 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
key="{{ lookup('pipe', 'ssh-keyscan -T 10 ' + ssh_known_hosts_hash|ternary('-H', '') + ' -t rsa ' + item) }}"
state=present
become: yes
with_items: "{{ ssh_known_hosts_global }}"
with_items: "{{ ssh_known_hosts_global_scan }}"
changed_when: no

- name: ensure ~/.ssh directory is present
Expand All @@ -53,13 +53,13 @@
state=directory
become: yes
with_items:
- "{{ ssh_known_hosts_user }}"
- "{{ ssh_known_hosts_user_scan }}"

- name: ensure ~/.ssh/known_hosts file is present
shell: "test -e ~{{ item.user }}/.ssh/known_hosts || touch ~{{ item.user }}/.ssh/known_hosts"
become: yes
with_items:
- "{{ ssh_known_hosts_user }}"
- "{{ ssh_known_hosts_user_scan }}"
changed_when: no

- name: setup user known_hosts
Expand All @@ -70,7 +70,7 @@
state=present
become: yes
with_subelements:
- "{{ ssh_known_hosts_user }}"
- "{{ ssh_known_hosts_user_scan }}"
- hosts
changed_when: no

Expand All @@ -83,5 +83,5 @@
state=file
become: yes
with_items:
- "{{ ssh_known_hosts_user }}"
- "{{ ssh_known_hosts_user_scan }}"
changed_when: no
16 changes: 8 additions & 8 deletions tasks/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
with_items:
- ssh_config
- ssh_config_path
- ssh_known_hosts_global
- ssh_known_hosts_global_scan
- ssh_known_hosts_global_path
- ssh_known_hosts_user
- ssh_known_hosts_user_scan

- name: validation | keys of ssh_known_hosts_user have dictionary with user key
- name: validation | keys of ssh_known_hosts_user_scan have dictionary with user key
fail:
msg="user {{ item }} on ssh_known_hosts_user variable is missing the user key"
msg="user {{ item }} on ssh_known_hosts_user_scan variable is missing the user key"
when: "{{ item.user is not defined }}"
with_items: "{{ ssh_known_hosts_user }}"
with_items: "{{ ssh_known_hosts_user_scan }}"

- name: validation | keys of ssh_known_hosts_user have dictionary with hosts key
- name: validation | keys of ssh_known_hosts_user_scan have dictionary with hosts key
fail:
msg="user {{ item }} on ssh_known_hosts_user variable is missing the hosts list"
msg="user {{ item }} on ssh_known_hosts_user_scan variable is missing the hosts list"
when: "{{ item.hosts is not defined }}"
with_items: "{{ ssh_known_hosts_user }}"
with_items: "{{ ssh_known_hosts_user_scan }}"
2 changes: 1 addition & 1 deletion tests/tasks/global_known_hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
- name: global_known_hosts | check available host names
command: "ssh-keygen {{ '-H' if ssh_known_hosts_hash }} -f {{ ssh_known_hosts_global_path }} -F {{ item }}"
changed_when: no
with_items: "{{ ssh_known_hosts_global }}"
with_items: "{{ ssh_known_hosts_global_scan }}"
become: yes
2 changes: 1 addition & 1 deletion tests/tasks/user_known_hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- name: user | check available host names on ~/.ssh/known_hosts
command: "ssh-keygen {{ '-H' if ssh_known_hosts_hash }} -f ~{{ item.0.user }}/.ssh/known_hosts -F {{ item.1 }}"
with_subelements:
- "{{ ssh_known_hosts_user }}"
- "{{ ssh_known_hosts_user_scan }}"
- hosts
become: yes
changed_when: no
4 changes: 2 additions & 2 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

vars:
debug: yes
ssh_known_hosts_global:
ssh_known_hosts_global_scan:
- github.com
ssh_known_hosts_user:
ssh_known_hosts_user_scan:
- user: "{{ ansible_user|default(ansible_env.USER) }}"
hosts:
- bitbucket.com
Expand Down

0 comments on commit b7efd3e

Please sign in to comment.