Skip to content

Commit

Permalink
Merge pull request #1 from adamantike/wireless-printers-support
Browse files Browse the repository at this point in the history
Add basic support for wireless printers
  • Loading branch information
jdauphant authored Jul 10, 2017
2 parents 8fa8e2f + 837df0f commit 5ff447f
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
- name: ensure needed dependancy are installed
apt: name=cups
- name: ensure needed dependencies are installed
apt:
name: "{{ item }}"
with_items:
- cups
- expect
when: ansible_os_family == "Debian"
tags: ["packages","brother"]

Expand All @@ -25,10 +29,63 @@
tags: ["packages","brother"]

- name: install and configure printers
shell: yes |{{brother_bin_dir}}/linux-brprinter-installer {{item}} chdir=/tmp
register: install_result
shell: |
# Exit without changes if the printer is already installed
set timeout 2
spawn /usr/bin/lpstat -a
expect {
"{{item}}" { exit 4 }
timeout {}
}
# Set larger timeout to wait for updates and cupsd restart
set timeout 180
# Run Brother script for printer
spawn {{brother_bin_dir}}/linux-brprinter-installer {{item}}
expect {
# Prompt 1: OK? [y/N]
"OK?" {
send "y\r"
exp_continue
}
# Prompt 2: Do you agree? [Y/n]
# This prompt does not appear if you already agreed
# Also, it can appear multiple times, depending on the needed packages
# to download
"Do you agree" {
send "y\r"
exp_continue
}
# Prompt 3: Will you specify the Device URI? [Y/n]
"specify the Device URI" {
send "y\r"
exp_continue
}
# Prompt 4: select the number of destination Device URI.
# "A" is the Auto option
"number of destination Device URI" {
send "A\r"
exp_continue
}
# Prompt 5: Test Print? [y/N]
"Test Print" {
send "n\r"
exp_continue
}
"Hit Enter" {
send "\r"
exp_continue
}
# Script finished
eof {}
}
args:
executable: /usr/bin/expect
chdir: /tmp
with_items: "{{brother_printers_to_install}}"
changed_when: "'Invalid IP address' in install_result.stderr"
failed_when: "'Invalid IP address' not in install_result.stderr"
ignore_errors: True
register: response
changed_when: response.rc == 0
failed_when: response.rc != 0 and response.rc != 4
tags: ["packages","brother"]

0 comments on commit 5ff447f

Please sign in to comment.