Your IP : 3.15.182.201


Current Path : /etc/ansible/roles/sphinx/tasks/
Upload File :
Current File : //etc/ansible/roles/sphinx/tasks/sites-cache_directory-execute.yml

---
# create temporary directory
# copy php script into the directory and run it
# delete temporary directory
- name: create main temporary directory
  file:
    path: "{{ cache_directory  }}"
    state: directory
    mode: 0750
    owner: "{{ bx_ansible_owner  }}"
    group: "{{ bx_ansible_group }}"
  delegate_to: "{{ php_server }}"

- name: generate unique id
  shell: echo "`date +"%Y%m%d%H%M%S"`-$(cat /dev/urandom | tr -cd [:alpha:] | tr '[:upper:]' '[:lower:]' | head -c 4)"
  register: bx_unique_id

- name: create site directory
  file: 
    path: "{{ cache_directory  }}/{{ item.SiteName  }}-{{ bx_unique_id.stdout }}"
    state: directory
    mode: 0750
    owner: "{{ bx_ansible_owner  }}"
    group: "{{ bx_ansible_group }}"
  with_items: "{{ bx_sites_info }}"
  delegate_to: "{{ php_server }}"

- name: create host directory
  file: 
    path: "{{ cache_directory  }}/{{ item.SiteName  }}-{{ bx_unique_id.stdout }}/{{ inventory_hostname }}"
    state: directory
    mode: 0750
    owner: "{{ bx_ansible_owner  }}"
    group: "{{ bx_ansible_group }}"
  with_items: "{{ bx_sites_info }}"
  delegate_to: "{{ php_server }}"

- name: create php-script
  template: 
    src: "{{ php_script }}.j2"
    dest: "{{ cache_directory }}/{{ item.SiteName }}-{{ bx_unique_id.stdout }}/{{ inventory_hostname }}/{{ php_script }}"
    owner: "{{ bx_ansible_owner }}"
    group: "{{ bx_ansible_group }}" 
    mode: 0640
  with_items: "{{ bx_sites_info }}"
  delegate_to: "{{ php_server }}"


- name: run php-script
  shell: php -f "{{ cache_directory }}/{{ item.SiteName }}-{{ bx_unique_id.stdout }}/{{ inventory_hostname }}/{{ php_script }}"
  become: yes
  become_user: "{{ bx_ansible_executer }}"
  with_items: "{{ bx_sites_info }}"
  delegate_to: "{{ php_server }}"

- name: delete temporary directory
  file: 
    path: "{{ cache_directory }}/{{ item.SiteName }}-{{ bx_unique_id.stdout }}"
    state: absent
  with_items: "{{ bx_sites_info }}"
  delegate_to: "{{ php_server }}"
  when: "ansible_playbook_debug != 'DEBUG'"