---
- name: Add SSH authorized key for synchronize Moudle
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"

- name: Copy nginx.conf
  template: src=nginx.conf dest=/usr/local/openresty/nginx/conf/nginx.conf  owner=root group=root mode=0644

#- name: Remove Old Vhost Directory
#  local_action: file path=/tmp/vhost state=absent

- name: Remove Old Vhost Directory
  file :
    path: /usr/local/openresty/nginx/conf/vhost
    state: absent

- name: Sync Vhost Files
  synchronize:  # need input password in command line if ssh key is none.
    src: vhost
    dest: /usr/local/openresty/nginx/conf/
    delete: yes

# - name: Sync Vhost Config
#   copy: src=vhost dest=/usr/local/openresty/nginx/conf/  owner=root group=root mode=0644
# 
- name: Sync SSL Certificate
  copy: src=sslkey dest=/usr/local/openresty/nginx/conf/  owner=root group=root mode=0644  
 
- name: Check Configuration
  shell: /usr/local/openresty/nginx/sbin/nginx -t

- name: Reload /usr/local/openresty/nginx/
  shell: /usr/local/openresty/nginx/sbin/nginx -s reload
