---
- name: Create Agent NGINX Hosts Directory
  become: yes
  become_user: jingrow
  file:
    path: /home/jingrow/agent/nginx/hosts
    state: directory

- name: Create Agent NGINX Upstream Directory
  become: yes
  become_user: jingrow
  file:
    path: /home/jingrow/agent/nginx/upstreams
    state: directory

- name: Create NGINX Proxy Configuration File
  become: yes
  become_user: jingrow
  file:
    path: /home/jingrow/agent/nginx/proxy.conf
    state: touch

- name: Symlink NGINX Proxy Configuration File
  file:
    src: /home/jingrow/agent/nginx/proxy.conf
    dest: /etc/nginx/conf.d/proxy.conf
    state: link
    force: yes
    follow: no

- name: Setup Agent Proxy
  become: yes
  become_user: jingrow
  command: '/home/jingrow/agent/env/bin/agent setup proxy --domain {{ domain }} --jcloud-url {{ jcloud_url }}'
  args:
    chdir: /home/jingrow/agent
