You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
YAML
49 lines
1.4 KiB
YAML
---
|
|
|
|
# Parameters:
|
|
# playbook inventory
|
|
# stage := the type of the stage (e.g. dev, int, qa, prod)
|
|
# username := the default username to use for the ssh connection
|
|
|
|
#############################################################
|
|
# 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 }}
|
|
User {{ username }}
|
|
{% endfor %} |