Skip to content

Commit 621e462

Browse files
ansible: add role to update known_hosts on windows (#3402)
Added github-windows role. based on an already existing github role. It does the same job on Windows and is used in jenkins-worker/create.yml playbook. Refs: #3265
1 parent 0468a55 commit 621e462

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

ansible/playbooks/create-windows-custom-vm.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- hosts:
88
- "*-win*"
99
gather_facts: yes
10+
gather_subset: min
1011

1112
roles:
1213
- bootstrap

ansible/playbooks/jenkins/worker/create.yml

+3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232

3333
- hosts:
3434
- "*-win*"
35+
gather_facts: yes
36+
gather_subset: min
3537

3638
roles:
3739
- bootstrap
3840
- package-upgrade
3941
- baselayout-windows
4042
- visual-studio
4143
- jenkins-worker-windows
44+
- github-windows
4245

4346
pre_tasks:
4447
- name: check if secret is properly set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
3+
# Set up hosts to be able to checkout/fetch from github.com via SSH.
4+
5+
- name: Check if current user already has a .ssh directory
6+
win_stat: path='{{ansible_facts["env"]["USERPROFILE"]}}\.ssh'
7+
register: ssh_stat
8+
9+
- name: Create a .ssh directory for current user if missing
10+
win_file:
11+
path: '{{ansible_facts["env"]["USERPROFILE"]}}\.ssh'
12+
state: directory
13+
when: not ssh_stat.stat.exists
14+
15+
- name: Check if current user already has a known_hosts file
16+
win_stat: path='{{ansible_facts["env"]["USERPROFILE"]}}\.ssh\known_hosts'
17+
register: known_hosts_stat
18+
19+
- name: Create a known_hosts for current user if missing
20+
win_copy:
21+
src: '../github/files/github_known_hosts'
22+
dest: '{{ansible_facts["env"]["USERPROFILE"]}}\.ssh\known_hosts'
23+
when: not known_hosts_stat.stat.exists
24+
25+
- name: Add github known hosts to known_hosts file if present
26+
win_lineinfile:
27+
path: '{{ansible_facts["env"]["USERPROFILE"]}}\.ssh\known_hosts'
28+
line: '{{item}}'
29+
state: present
30+
loop: "{{lookup('file', '../github/files/github_known_hosts').splitlines()}}"
31+
when: known_hosts_stat.stat.exists
32+
33+
- name: Remove github bad hosts from known_hosts file if present
34+
win_lineinfile:
35+
path: '{{ansible_facts["env"]["USERPROFILE"]}}\.ssh\known_hosts'
36+
line: '{{item}}'
37+
state: absent
38+
loop: "{{lookup('file', '../github/files/github_bad_hosts').splitlines()}}"
39+
when: known_hosts_stat.stat.exists

0 commit comments

Comments
 (0)