pulitux 2 роки тому
батько
коміт
43f1cfe7ae

+ 3 - 0
printing-auto/ansible.cfg

@@ -0,0 +1,3 @@
+[defaults]
+inventory=./inventory
+remote_user=devops

+ 3 - 0
printing-auto/inventory

@@ -0,0 +1,3 @@
+serverb.lab.example.com
+[clients]
+servera.lab.example.com

+ 19 - 0
printing-auto/printer-accept.yml

@@ -0,0 +1,19 @@
+---
+- name: Configure a print queue to accept jobs
+  hosts: clients
+  gather_facts: no
+  become: yes
+  vars:
+    queue_name: "my-printer"
+  tasks:
+    - name: Confirm the print queue exists
+      command: lpstat -p "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+
+    - name: Tune the print queue to accept jobs
+      command: cupsaccept "{{ queue_name }}"
+      when: cmdout.rc == 0
+
+

+ 55 - 0
printing-auto/printer-create.yml

@@ -0,0 +1,55 @@
+---
+- name: Install CUPS and create a print queue
+  hosts: clients
+  gather_facts: no
+  become: yes
+  vars:
+    print_packages:
+    - cups
+    - avahi
+    print_services:
+    - avahi-daemon
+    - cups
+    print_ports:
+    - mdns
+    queue_name: "my-printer"
+    dev_uri: "ipp://serverc.lab.example.com:631/printers/rht-printer"
+  tasks:
+    - name: Install the CUPS and Avahi packages
+      yum:
+        name: "{{ print_packages }}"
+        state: latest
+
+    - name: Enable and start the CUPS and Avahi services
+      service:
+        name: "{{ item }}"
+        state: started
+        enabled: yes
+      loop: "{{ print_services }}"
+
+    - name: Open the mDNS firewall port
+      firewalld:
+        service: "{{ item }}"
+        state: enabled
+        permanent: yes
+        immediate: yes
+      loop: "{{ print_ports }}"
+
+    - name: Check if print queue already exists
+      command: lpstat -p "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+
+    - name: Create the print queue
+      command: lpadmin -p "{{ queue_name }}" -v "{{ dev_uri }}" -m everywhere -E
+      when: cmdout.rc != 0
+
+    - name: Check default print queue
+      command: lpstat -d 
+      register: curr_dest
+      changed_when: false
+
+    - name: Make the new print queue the default
+      command: lpadmin -d "{{ queue_name }}"
+      when: curr_dest['stdout'] | regex_replace('^(.*):.') != queue_name

+ 17 - 0
printing-auto/printer-destroy.yml

@@ -0,0 +1,17 @@
+---
+- name: Remove a print queue
+  hosts: clients
+  gather_facts: no
+  become: yes
+  vars:
+    queue_name: "my-printer"
+  tasks:
+    - name: Check if print queue exists
+      command: lpstat -p "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+
+    - name: Delete the print queue
+      command: lpadmin -x "{{ queue_name }}"
+      when: cmdout.rc == 0

+ 17 - 0
printing-auto/printer-reject.yml

@@ -0,0 +1,17 @@
+---
+- name: Configure a print queue to reject jobs
+  hosts: clients
+  gather_facts: no
+  become: yes
+  vars:
+    queue_name: "my-printer"
+  tasks:
+    - name: Confirm the print queue exists
+      command: lpstat -p "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+
+    - name: Tune the print queue to reject jobs
+      command: cupsreject "{{ queue_name }}"
+      when: cmdout.rc == 0

+ 3 - 0
printing-review/ansible.cfg

@@ -0,0 +1,3 @@
+[defaults]
+inventory=./inventory
+remote_user=root

+ 2 - 0
printing-review/inventory

@@ -0,0 +1,2 @@
+servera.lab.example.com
+serverb.lab.example.com

+ 48 - 0
printing-review/printer-create.yml

@@ -0,0 +1,48 @@
+---
+- name: Install CUPS and create a print queue
+  hosts:
+  gather_facts: no
+  vars:
+    print_packages:
+    -
+    -
+    print_services:
+    -
+    -
+    print_ports:
+    -
+    queue_name: "local_print_queue_name"
+    device_uri: "URI_to_remote_print_queue"
+  tasks:
+    - name: Install the CUPS and Avahi packages
+      yum:
+        name: "{{ print_packages }}"
+        state:
+    - name: Enable and start the CUPS and Avahi services
+      systemd:
+        name: "{{ item }}"
+        state:
+        enabled:
+      loop: "{{ print_services }}"
+    - name: Open the mDNS firewall port
+      firewalld:
+        service: "{{ item }}"
+        state:
+        permanent:
+        immediate:
+      loop: "{{ print_ports }}"
+    - name: Check if print queue already exists
+      command:
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+    - name: Create the print queue
+      command:
+      when: cmdout.rc != 0
+    - name: Check default printer
+      command:
+      register: curr_dest
+      changed_when: false
+    - name: Make the new print queue the default
+      command:
+      when: curr_dest['stdout'] | regex_replace('^(.*):.') != queue_name

+ 15 - 0
printing-review/printer-disable.yml

@@ -0,0 +1,15 @@
+---
+- name: Configure a print queue to stop printing
+  hosts: serverb.lab.example.com
+  gather_facts: no
+  vars:
+    queue_name: "lab-printer"
+  tasks:
+    - name: Confirm the print queue exists
+      command: lpstat -v  "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+    - name: Disable the print queue
+      command: cupsdisable "{{ queue_name }}"
+      when: cmdout.rc == 0

+ 15 - 0
printing-review/printer-enable.yml

@@ -0,0 +1,15 @@
+---
+- name: Configure a print queue to start printing
+  hosts: serverb.lab.example.com
+  gather_facts: no
+  vars:
+    queue_name: "lab-printer"
+  tasks:
+    - name: Confirm the print queue exists
+      command: lpstat -v  "{{ queue_name }}"
+      register: cmdout
+      ignore_errors: true
+      changed_when: false
+    - name: Enable the print queue
+      command: cupsaccept  "{{ queue_name }}"
+      when: cmdout.rc == 0