forked from redhat-cop/agnosticd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_infra.yml
80 lines (73 loc) · 2.8 KB
/
post_infra.yml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
- name: Build inventory
hosts: localhost
connection: local
become: false
gather_facts: false
tags:
- step002
tasks:
- name: Set up inventory for mapping
when: target_host is mapping
block:
- name: Fail when no key provided
when:
- '"ansible_ssh_private_key_content" in target_host'
- '"ansible_ssh_private_key_file" in target_host'
ansible.builtin.fail:
msg: You cannot set both ansible_ssh_private_key_content and ansible_ssh_private_key_file
- name: Prepare ssh key from provided variable
when: '"ansible_ssh_private_key_content" in target_host'
block:
- name: Prepare ssh_key from provided content
ansible.builtin.copy:
content: "{{ target_host.ansible_ssh_private_key_content }}"
dest: "{{ output_dir }}/ssh_key.pem"
mode: "0600"
- name: Set fact for private key file
ansible.builtin.set_fact:
target_host_ansible_ssh_private_key_file: "{{ output_dir }}/ssh_key.pem"
- name: Add bastion to inventory
ansible.builtin.add_host:
name: >-
{{
target_host.name
| default(target_host.hostname)
| default(target_host.ansible_host)
}}
ansible_host: "{{ target_host.ansible_host | default(omit) }}"
group: ocp_bastions
ansible_user: "{{ target_host.ansible_user | default(omit) }}"
ansible_port: "{{ target_host.ansible_port | default(omit) }}"
ansible_ssh_private_key_file: >-
{{ target_host.ansible_ssh_private_key_file
| default(target_host_ansible_ssh_private_key_file)
| default(omit) }}
ansible_ssh_extra_args: "{{ target_host.ansible_ssh_extra_args | default(omit) }}"
ansible_ssh_pipelining: true
output_dir: "{{ output_dir }}"
- name: Add bastion to inventory (simple hostname)
when: target_host is string
ansible.builtin.add_host:
name: "{{ target_host }}"
group: ocp_bastions
ansible_connection: "{{ 'local' if target_host == 'localhost' else omit }}"
ansible_python_interpreter: "{{ ansible_playbook_python if target_host == 'localhost' else omit }}"
output_dir: "{{ output_dir }}"
# Re-run include vars after add_host
- import_playbook: ../../include_vars.yml
- name: Set ansible_python_interpreter to virtualenv if available
hosts: ocp_bastions
become: false
gather_facts: false
tags:
- step002
tasks:
- name: Check if desired virtualenv is available on the host
ansible.builtin.stat:
path: "{{ ocp_workloads_virtualenv_path }}/bin/python"
register: r_virtualenv
- name: Set Ansible Python interpreter to virtualenv
when: r_virtualenv.stat.exists
ansible.builtin.set_fact:
ansible_python_interpreter: "{{ ocp_workloads_virtualenv_path }}/bin/python"