{"id":5939,"sha1":"7f890fedfa84b11d9479ae3ea85cd5b196db7649","playbook":{"id":3819,"items":{"plays":1,"tasks":3,"results":3,"hosts":1,"files":1,"records":0},"arguments":{"version":null,"verbosity":2,"private_key_file":"/home/ssh-gateway/.ssh/id_rsa","remote_user":"root","connection":"ssh","timeout":null,"ssh_common_args":null,"sftp_extra_args":null,"scp_extra_args":null,"ssh_extra_args":null,"ask_pass":false,"connection_password_file":null,"force_handlers":false,"flush_cache":false,"become":false,"become_method":"sudo","become_user":null,"become_ask_pass":false,"become_password_file":null,"tags":["all"],"skip_tags":[],"check":false,"diff":false,"inventory":["/home/ssh-gateway/ansible/kuly/bash-kvm-inventory-dev.sh"],"listhosts":false,"subset":"perfect-antelope.man-1.solus.stage.town","extra_vars":"Not saved by ARA as configured by 'ignored_arguments'","vault_ids":[],"ask_vault_pass":false,"vault_password_files":[],"forks":20,"module_path":null,"syntax":false,"listtasks":false,"listtags":false,"step":false,"start_at_task":null,"args":["RM10136_firewall_ssh_deny.yaml"]},"labels":[{"id":1,"name":"remote_user:root"},{"id":2,"name":"check:False"},{"id":3,"name":"tags:all"},{"id":228,"name":"subset:perfect-antelope.man-1.solus.stage.town"}],"started":"2025-09-16T10:21:03.629359+01:00","ended":"2025-09-16T10:21:06.039686+01:00","duration":"00:00:02.410327","name":null,"ansible_version":"2.16.11","client_version":"1.7.3","python_version":"3.10.10","server_version":"1.7.3","status":"completed","path":"/home/ssh-gateway/ansible/kuly/RM10136_firewall_ssh_deny.yaml","controller":"ssh-gw-4.layershift.com","user":"root"},"content":"---\n- name: Playbook to deny ssh for plesk servers that do not have shell users\n  hosts: all\n  gather_facts: false\n  tasks:\n    - name: Get server info\n      plesk_info:\n      register: plsk\n    - name: On plesk server run the script\n      when: plsk.plesk_found\n      ansible.builtin.shell: |\n        set -o pipefail\n        set -e\n        homedirs=$(awk '/HTTPD_VHOSTS_D/ {print $2}' /etc/psa/psa.conf)\n        bashes=$(grep \"$homedirs\" /etc/passwd | grep -v \"/bin/false\" | wc -l)\n        if [ \"$bashes\" -eq 0 ]; then\n          rule_id=$(/usr/sbin/plesk ext firewall --list-json | jq -r '.[] | select(.class==\"ssh\") | .id')\n          if [ -n \"$rule_id\" ]; then\n            echo \"Blocking SSH via Plesk firewall (rule ID: $rule_id)...\"\n            /usr/sbin/plesk ext firewall --set-rule -id \"$rule_id\" -action deny && /usr/sbin/plesk ext firewall --apply -auto-confirm-this-may-lock-me-out-of-the-server\n          else\n            echo \"SSH rule not found in firewall!\"\n          fi\n        else\n          echo \"We have users with shells, skipping\"\n        fi\n      args:\n        executable: /bin/bash\n      register: script_result\n      changed_when: \"'Blocking SSH' in script_result.stdout\"\n      failed_when: false\n    - name: Display results\n      ansible.builtin.debug:\n        msg: \"{{ script_result.stdout_lines }}\"\n","created":"2025-09-16T10:21:03.658323+01:00","updated":"2025-09-16T10:21:03.658355+01:00","path":"/home/ssh-gateway/ansible/kuly/RM10136_firewall_ssh_deny.yaml"}