--- # This playbook dumps all ip addresses from Hetzner Cloud saving it into local file. # A prefix "route" will be added, to easily use it within custom ovpn configuration. # # Parameters: # playbook inventory # stage := the name of the stage (e.g. dev, int, qa, prod) # Example: # STAGE=ext && ansible-playbook dump-hcloud-ips.yml -e "stage=${STAGE}" --vault-password-file=~/.ansible-vault-pass-${STAGE} ############################################################# # Creating inventory dynamically for given parameters # ############################################################# - hosts: localhost connection: local gather_facts: false pre_tasks: - name: "Import constraints check" import_tasks: tasks/constraints_check.yml become: false tags: - always # Add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" add_host: name: "{{ stage }}-virtual-host-to-read-groups-vars" groups: - "stage_{{ stage }}" changed_when: False ############################################################# # Dumping ip addresses from hcloud with given stage # ############################################################# - hosts: "{{ stage }}-virtual-host-to-read-groups-vars" serial: "{{ serial_number | default(1) }}" gather_facts: false connection: local pre_tasks: - name: "Reading current server groups from hetzner" include_role: name: hetzner-ansible-hcloud tasks_from: _read_server_infos with_items: [ { name: "all", label_selector: "stage={{ stage }}", } ] loop_control: loop_var: current_server_group - name: "Reading info about current loadbalancers from hetzner" include_role: name: hetzner-ansible-hcloud tasks_from: _read_load_balancer_infos with_items: [ { name: "all", #label_selector: "stage={{ stage }}", # There are no useful labels at the moment. Todo: Create labels for load balancers like stage=dev } ] loop_control: loop_var: current_load_balancer_group tasks: - name: 'Save Hetzner Server ip adresses in ~/hcloud_ip_addresses.txt' blockinfile: marker: "## {mark} managed by ansible (hosts config for {{ stage }}) ##" path: '~/hcloud_ip_addresses.txt' state: present create: yes block: | {% for host in server_group_infos_all %} # {{ host.name }} route {{ host.ip }} {% endfor %} - name: 'Save Hetzner loadbalancer ip adresses in ~/hcloud_ip_addresses.txt' blockinfile: marker: "## {mark} managed by ansible (load balancer config for {{ stage }}) ##" path: '~/hcloud_ip_addresses.txt' state: present create: yes block: | {% for host in load_balancer_group_infos_all %} # {{ host.name }} route {{ host.ip }} {% endfor %}