--- - name: Deploy terraform hosts: localhost gather_facts: false tasks: - name: Deploy terraform community.general.terraform: project_path: ../terraform/ state: present complex_vars: true variables: "{{ terraform_vars }}" register: tf_out - debug: var=tf_out - add_host: name: "{{ item.key }}" ansible_host: "{{ item.value }}" group: web loop: "{{ tf_out.outputs.server_ips.value | dict2items }}" - add_host: name: "lb" ansible_host: "{{ tf_out.outputs.lb_public_ip.value }}" group: lb - name: Setup loadbalancer hosts: lb vars_files: - vault.yaml vars: caddy: server_name: wordpress-jr.senecops.com lb_targets: - 10.0.0.3:80 - 10.0.0.4:80 - 10.0.0.5:80 mysql: hostrange: "10.0.0.0/255.255.255.0" roles: - caddy - mysql - name: Setup LEMP stack on application servers hosts: web vars_files: - vault.yaml vars: server_name: wordpress-jr.senecops.com wordpress: dir: /var/www/html/wordpress php: version: 8.1 gluster: brick_dir: /srv/data/wordpress mount_dir: /var/www/html/wordpress vol_name: wordpress_vol dir_owner: wordpress dir_group: www-data cluster: - 10.0.0.3 - 10.0.0.4 - 10.0.0.5 pre_tasks: - debug: var=ansible_ens10.ipv4.address roles: - nginx - php - glusterfs - wordpress - name: Remove public IP hosts: localhost gather_facts: false tasks: - name: Remove public Ip community.general.terraform: project_path: ../terraform/ state: present complex_vars: true variables: "{{ terraform_vars | combine({'public_ipv4': False}) }}" register: tf_out - debug: var=tf_out