---
- name: Set up Samsung xpress c460w
  hosts: localhost
  vars:
    driver_version: "V1.00.39_01.17"
  connection: local
  become: false
  tasks:
    - name: Have driver installed allready
      stat:
        path: /opt/samsung/scanner/.version
      register: have_printer
    - name: Get driver
      ansible.builtin.command:
        chdir: /tmp
        cmd: wget https://ftp.hp.com/pub/softlib/software13/printers/SS/SL-M4580FX/uld_{{ driver_version }}.tar.gz
      when: not have_printer.stat.exists
    - name: Extract driver
      ansible.builtin.command:
        chdir: /tmp
        cmd: tar xf uld_{{ driver_version }}.tar.gz
      when: not have_printer.stat.exists
    - name: Extract driver
      ansible.builtin.command:
        chdir: /tmp/uld
        cmd: sh ./install.sh
      environment:
        CONTINUE_INSTALL: "y"
        AGREE_EULA: "y"
        QUIT_INSTALL: "n"
        UNINSTALL_LECAGY: "y"
        CONFIGURE_FIREWALL: "n"
        SKIP_EULA_PAGER: "y"
      become: true
      when: not have_printer.stat.exists
    - name: Cleanup
      ansible.builtin.command:
        chdir: /tmp
        cmd: rm -rf  uld_{{ driver_version }}.tar.gz uld/
      become: true
      when: not have_printer.stat.exists
