# administer this service by browsing to localhost:631
- name: Install cups package
  package:
    name: cups
    state: present
  when: cups_install
  tags:
    - download

- name: Install our own /etc/cups/cupsd.conf from template, to permit local LAN admin
  template:
    src: cupsd.conf
    dest: /etc/cups/cupsd.conf

- name: Install /etc/{{ apache_config_dir }}/cups.conf from template
  template:
    src: cups.conf
    dest: "/etc/{{ apache_config_dir }}/"

- name: Create symlink cups.conf from sites-enabled to sites-available (debuntu)
  file:
    src: /etc/apache2/sites-available/cups.conf
    dest: /etc/apache2/sites-enabled/cups.conf
    state: link
  when: cups_enabled and is_debuntu

- name: Enable & Start services 'cups' and 'cups-browsed' (OS's other than Fedora 18)
  service:
    name: "{{ item }}"
    state: started
    enabled: yes
  with_items:
    - cups
    - cups-browsed
  when: cups_enabled and not is_F18

- name: Enable & Start service 'cups' (Fedora 18, for XO laptops)
  systemd:
    name: cups
    state: started
    enabled: yes
  when: cups_enabled and is_F18

- name: Permit headless admin of CUPS -- only works when CUPS daemon is running
  shell: "cupsctl --remote-admin"
  when: cups_enabled

- name: Disable both CUPS services (OS's other than Fedora 18)
  systemd:
    name: "{{ item }}"
    state: stopped
    enabled: no
  with_items:
    - cups
    - cups-browsed
  when: not cups_enabled and not is_F18

- name: Disable services for CUPS (Fedora 18, for XO laptops)
  systemd:
    name: cups
    state: stopped
    enabled: no
  when: not cups_enabled and is_F18

- name: Add 'cups' variable values to {{ iiab_ini_file }}
  ini_file:
    path: "{{ iiab_ini_file }}"
    section: cups
    option: "{{ item.option }}"
    value: "{{ item.value }}"
  with_items:
    - option: name
      value: CUPS
    - option: description
      value: '"CUPS (Common UNIX Printing System) is a modular printing system that allows a computer to act as a print server. A computer running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer."'
    - option: installed
      value: "{{ cups_install }}"
    - option: enabled
      value: "{{ cups_enabled }}"
