03__configure_app_servers.yml.md

The source files for this tutorial can be downloaded from its GitHub repository, or cloned into your current working directory using the command git clone https://github.com/ionos-cloud/module-ansible.git before changing into the module-ansible/docs/tutorials/07__introducing_the_application_load_balancer sub-directory.

01__create_jumpbox_and_nlb.yml
---
- hosts: app-servers

  vars_files:
    - vars.yml


  tasks:
    # Apply some basic network configurations needed, since these VMs are
    # behind the NAT Gateway and don't have access to a 'full' DHCP server
    - name: Set our default route
      ansible.builtin.shell: "ip route add default via {{ nat_gateway.ip }} || true"


    # Arguably not the most robust solution, but while an approach based upon,
    # say, https://stackoverflow.com/a/67379573 would guarantee the resulting
    # file is always valid, assuming the level of indention doesn't change,
    # the following is simpler, and doesn't remove any comments that said file
    # might contain
    - name: Add our default route to /etc/netplan/50-cloud-init.yaml to make it persistent
      blockinfile:
        path: /etc/netplan/50-cloud-init.yaml
        insertbefore: "match:"
        block: |
          

<div data-gb-custom-block data-tag="filter" data-width='12' data-idth='12' data-first='true'>

          routes:
            - to: default
              via: 192.168.8.1
          

</div>

    - name: Ensure 'DNS=212.227.123.16 212.227.123.17' is in the '[Resolve]' section of /etc/systemd/resolved.conf
      community.general.ini_file:
        path: /etc/systemd/resolved.conf
        section: Resolve
        option: DNS
        value: 212.227.123.16 212.227.123.17
        state: present


    - name: Restart the systemd-resolved service
      ansible.builtin.service:
        name: systemd-resolved
        state: restarted




    - name: Update repositories cache and upgrade the system
      ansible.builtin.apt:
        upgrade: dist
        update_cache: yes
        cache_valid_time: 3600


    - name: Install nginx
      ansible.builtin.package:
        name:
          - nginx
        state: present


    - name: And create our per-host index.html files on the remote servers
      ansible.builtin.template:
        src: templates/index.html.j2
        dest: /var/www/html/index.html

Last updated