---

- name: "Check if operator profile exists"
  command: "docker exec cobbler cobbler profile find --name=operator"
  register: profile_state
  changed_when: False

- name: "Calculate total number of hosts in this robot"
  set_fact:
    total_machines: "1"
    robot_has_operator: "0"
    machine_info: "{{ cobbler_operator_machine_info }}"
    robot_info: "{{ cobbler_operator_robot_info }}"

- name: "Render the preseed file to /etc/docker-compose/cobbler/dist"
  template:
    src: "ubuntu-14.04.5.seed"
    dest: "/etc/docker-compose/cobbler/dist/operator.seed"
  register: preseed_state

- name: "Copy the preseed file to cobbler's /var/lib/cobbler/kickstarts/ location"
  command: "docker exec cobbler cp /dist/operator.seed /var/lib/cobbler/kickstarts/"
  when: preseed_state.changed

- name: "Add the operator profile"
  command: "docker exec cobbler cobbler profile add
    --name operator
    --distro ubuntu_14.04.5-x86_64
    --kickstart /var/lib/cobbler/kickstarts/operator.seed"
  when: profile_state.stdout == ""

- name: "Update the operator profile"
  command: "docker exec cobbler cobbler profile edit
    --name operator
    --distro ubuntu_14.04.5-x86_64
    --kickstart /var/lib/cobbler/kickstarts/operator.seed"
  when: profile_state.stdout != "" and preseed_state.changed
