<commit_before>---

- name: Create virtualhosts
  template:
    src: "{{ item.nginx.template | default('default') }}"
    dest: "{{ global.nginx.path | default('/etc/nginx/vhosts') }}/{{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}.conf"
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "present") | notbyattr("nginx", false) | list
  when: item.nginx != false
  register: create_virtualhost
  become: true

- name: Remove disabled projects virtualhosts
  file:
    path: "{{ global.nginx.path | default('/etc/nginx/vhosts') }}/{{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}.conf"
    state: absent
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "absent") | list
  register: remove_virtualhost

- name: Handle hosts in system hosts file
  lineinfile:
    dest: /etc/hosts
    regexp: "^127\\.0\\.0\\.1   {{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}$"
    line: "127.0.0.1   {{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}"
    state: "{{ (item.nginx != false) | ternary('present', 'absent') }}"
  with_items: items.results | map(attribute='ansible_facts') | list
  become: true

- name: Restart nginx
  service:
    name: nginx
    state: restarted
  when: create_virtualhost.changed or remove_virtualhost.changed
  become: true

- name: Check if service phpX-fpm exists
  stat:
    path: "/etc/init.d/{{ item }}"
  register: service_status
  when: create_virtualhost.changed or remove_virtualhost.changed
  with_items:
    - php5-fpm
    - php5.6-fpm
    - php7.0-fpm
  become: true

- name: Restart phpX-fpm
  service:
    name: "{{ item.item }}"
    state: restarted
  with_items: service_status.results
  when: (create_virtualhost.changed or remove_virtualhost.changed) and item.stat.exists
  become: true
<commit_msg>Fix missing "become" in nginx role<commit_after>---

- name: Create virtualhosts
  template:
    src: "{{ item.nginx.template | default('default') }}"
    dest: "{{ global.nginx.path | default('/etc/nginx/vhosts') }}/{{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}.conf"
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "present") | notbyattr("nginx", false) | list
  when: item.nginx != false
  register: create_virtualhost
  become: true

- name: Remove disabled projects virtualhosts
  file:
    path: "{{ global.nginx.path | default('/etc/nginx/vhosts') }}/{{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}.conf"
    state: absent
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "absent") | list
  register: remove_virtualhost
  become: true

- name: Handle hosts in system hosts file
  lineinfile:
    dest: /etc/hosts
    regexp: "^127\\.0\\.0\\.1   {{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}$"
    line: "127.0.0.1   {{ global.nginx.hostname | default('[[project]].dev') | regex_replace('\\[\\[project\\]\\]', item.project) }}"
    state: "{{ (item.nginx != false) | ternary('present', 'absent') }}"
  with_items: items.results | map(attribute='ansible_facts') | list
  become: true

- name: Restart nginx
  service:
    name: nginx
    state: restarted
  when: create_virtualhost.changed or remove_virtualhost.changed
  become: true

- name: Check if service phpX-fpm exists
  stat:
    path: "/etc/init.d/{{ item }}"
  register: service_status
  when: create_virtualhost.changed or remove_virtualhost.changed
  with_items:
    - php5-fpm
    - php5.6-fpm
    - php7.0-fpm
  become: true

- name: Restart phpX-fpm
  service:
    name: "{{ item.item }}"
    state: restarted
  with_items: service_status.results
  when: (create_virtualhost.changed or remove_virtualhost.changed) and item.stat.exists
  become: true

{'fraction_non_alphanumeric': 0.18037974683544303, 'fraction_numerical': 0.008276533592989289, 'mean_word_length': 3.777906976744186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5494591', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1411, 'n_words': 291}