---
-
  name: "Creating Installation Directories"
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    mode: '0755'
  with_items:
    - "{{ python_simple_web_server_path }}/images"
    - "{{ python_simple_web_server_path }}/ids"

-
  name: "Installing uploadserver for Python Web Server"
  ansible.builtin.pip:
    name: "uploadserver"
    extra_args: --user --break-system-packages

-
  name: "Registering Output of IP Address"
  ansible.builtin.command: "cat {{ completed_dir }}/ipaddress.yml"
  changed_when: false
  register: netoutput

-
  name: "Placing Python Simple HTTP Server Service file"
  become: true
  ansible.builtin.template:
    owner: "{{ item.owner }}"
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: '0644'
  loop:
    - { src: 'pythonserve.service.j2', dest: '/etc/systemd/system/pythonserve.service', owner: '{{ service_user }}' }
    - { src: 'environment.j2', dest: '/etc/pythonserv', owner: '{{ service_user }}' }
    - { src: 'index.html.j2', dest: '{{ python_simple_web_server_path }}/welcome.html', owner: '{{ service_user }}' }
    - { src: 'styles.css', dest: '{{ python_simple_web_server_path }}/styles.css', owner: '{{ service_user }}' }
    - { src: 'cockpit.conf.j2', dest: '/etc/cockpit/cockpit.conf', owner: '{{ service_user }}' }

-
  name: "Starting Python Simple HTTP server"
  ansible.builtin.service:
    name: pythonserve
    state: started
    enabled: true

-
  name: "Ansible Playbook Into Support Bundle"
  community.general.archive:
    mode: '0777'
    path: "/vagrant/ansible"
    dest: "/vagrant/support-bundle/ansible-roles.zip"
    format: zip

-
  name: "Recording Installers"
  ansible.builtin.command: tree -J /vagrant/installers
  register: installers
  changed_when: false

-
  name: "Writing included installers to /vagrant/support-bundle/installers.json"
  ansible.builtin.copy:
    content: "{{ installers.stdout_lines }}"
    dest: "/vagrant/support-bundle/installers.json"
    force: false
    mode: 'a+x'

-
  name: "Including Domino One Touch autoconfigure to /vagrant/support-bundle/autoconfigure.log"
  become: true
  when: domino_home_dir is defined
  ansible.builtin.copy:
    src: "{{ domino_home_dir }}/IBM_TECHNICAL_SUPPORT/autoconfigure.log"
    dest: "/vagrant/support-bundle/autoconfigure.log"
    force: false
    mode: 'a+x'
    remote_src: true

-
  name: "Recording Completed Roles"
  ansible.builtin.command: tree -J /vagrant/completed
  register: completed
  changed_when: false

-
  name: "Writing current completed roles to /vagrant/support-bundle/completed.json"
  ansible.builtin.copy:
    content: "{{ completed.stdout_lines }}"
    dest: "/vagrant/support-bundle/completed.json"
    force: false
    mode: 'a+x'

-
  name: "Checking Python Simple HTTP server is listening on port {{ startcloud_quick_start_port_forwards[0].guest }}"
  ansible.builtin.wait_for:
    port: "{{ startcloud_quick_start_port_forwards[0].guest }}"
    delay: 5
    timeout: 60
    msg: "Timeout waiting for {{ startcloud_quick_start_port_forwards[0].guest }} to respond"
  register: port_check
  ignore_errors: true

-
  name: "Zip Support Bundle"
  community.general.archive:
    mode: '0777'
    path: "/vagrant/support-bundle"
    dest: "{{ python_simple_web_server_path }}/support-bundle.zip"
    format: zip

-
  name: "Restarting Cockpit"
  ansible.builtin.systemd:
    state: restarted
    daemon_reload: true
    name: cockpit
