chore: new playbook to update local ssh config file
{for each host on stage}
Host dev-...
HostName 1.2.3.4
{endfor}
master
parent
79a423f7b7
commit
ebad4eade4
@ -0,0 +1,31 @@
|
||||
---
|
||||
|
||||
- name: "Gathering current server infos for group {{ current_server_group.name }} from hetzner"
|
||||
hcloud_server_info:
|
||||
api_token: "{{ hetzner_authentication_token }}"
|
||||
label_selector: "{{ current_server_group.label_selector }}"
|
||||
register: current_server_infos
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
tags:
|
||||
- update_config
|
||||
|
||||
- name: "Setting server group as fact: server_group_infos_{{ current_server_group.name }}"
|
||||
set_fact:
|
||||
server_group_infos_{{ current_server_group.name }}: "{{ current_server_infos.hcloud_server_info | json_query(querystr) }}"
|
||||
vars:
|
||||
querystr: "[*].{id: id, name: name, ip: ipv4_address}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
tags:
|
||||
- update_config
|
||||
|
||||
- name: "Printing server group {{ current_server_group.name }}"
|
||||
debug:
|
||||
msg: "{{ lookup('vars', 'server_group_infos_' + current_server_group.name) }}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
tags:
|
||||
- update_config
|
||||
when:
|
||||
- debug
|
||||
@ -1,21 +0,0 @@
|
||||
---
|
||||
|
||||
- name: 'apply setup to {{ host | default("all") }}'
|
||||
hosts: '{{ host | default("all") }}'
|
||||
serial: "{{ serial_number | default(5) }}"
|
||||
gather_facts: no
|
||||
become: no
|
||||
|
||||
pre_tasks:
|
||||
- name: "Check if ansible version is at least 2.10.x"
|
||||
assert:
|
||||
that:
|
||||
- ansible_version.major >= 2
|
||||
- ansible_version.minor >= 10
|
||||
msg: "The ansible version has to be at least ({{ ansible_version.full }})"
|
||||
|
||||
roles:
|
||||
- role: hetzner-state
|
||||
vars:
|
||||
hetzner_state: 'started'
|
||||
when: "'hcloud' in group_names"
|
||||
@ -1,21 +0,0 @@
|
||||
---
|
||||
|
||||
- name: 'apply setup to {{ host | default("all") }}'
|
||||
hosts: '{{ host | default("all") }}'
|
||||
serial: "{{ serial_number | default(5) }}"
|
||||
gather_facts: no
|
||||
become: no
|
||||
|
||||
pre_tasks:
|
||||
- name: "Check if ansible version is at least 2.10.x"
|
||||
assert:
|
||||
that:
|
||||
- ansible_version.major >= 2
|
||||
- ansible_version.minor >= 10
|
||||
msg: "The ansible version has to be at least ({{ ansible_version.full }})"
|
||||
|
||||
roles:
|
||||
- role: hetzner-state
|
||||
vars:
|
||||
hetzner_state: 'stopped'
|
||||
when: "'hcloud' in group_names"
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
|
||||
# Parameters:
|
||||
# playbook inventory
|
||||
# stage := the type of the stage (e.g. dev, int, qa, prod)
|
||||
|
||||
#############################################################
|
||||
# Updating ssh config for servers with given stage
|
||||
#############################################################
|
||||
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
|
||||
pre_tasks:
|
||||
- name: "Check if ansible version is at least 2.10.x"
|
||||
assert:
|
||||
that:
|
||||
- ansible_version.major >= 2
|
||||
- ansible_version.minor >= 10
|
||||
msg: "The ansible version has to be at least ({{ ansible_version.full }})"
|
||||
|
||||
- name: "Reading current server groups from hetzner"
|
||||
include_role:
|
||||
name: hcloud
|
||||
tasks_from: _read_server_infos
|
||||
with_items: [
|
||||
{
|
||||
name: "all",
|
||||
label_selector: "stage={{ stage }}",
|
||||
}
|
||||
]
|
||||
loop_control:
|
||||
loop_var: current_server_group
|
||||
|
||||
tasks:
|
||||
- name: 'Insert/Update ssh config in ~/.ssh/config'
|
||||
blockinfile:
|
||||
marker: "# {mark} managed by ansible (hosts config for {{ stage }})"
|
||||
path: '~/.ssh/config'
|
||||
state: present
|
||||
create: yes
|
||||
block: |
|
||||
{% for host in server_group_infos_all %}
|
||||
Host {{ host.name }}
|
||||
HostName {{ host.ip }}
|
||||
{% endfor %}
|
||||
Loading…
Reference in New Issue