---
# Script to change an option=value of an entry into htdocs/conf/conf.php
#
# Examples to run the script:
# ansible-playbook -K bannedip.yml -i hosts-xxx -e 'target=targethost option=<your_option> value=<new_value>'
# ansible-playbook -K bannedip.yml -i hosts-xxx -e 'target=targethost option=<your_option> value=<new_value>' --limit=*.mydomain.com
#

- name: Unban an IP by Fail2Ban
  hosts: '{{target}}'
  become: yes
  vars:
    ip_a_debannir: "IP_À_DÉBANNIR"  # Remplacez IP_À_DÉBANNIR par l'adresse IP réelle à dé-bannir
    
  tasks:
    - name: Uban IP of all jails
      ansible.builtin.shell: |
        for jail in $(fail2ban-client status | grep "Jail list:" | sed 's/.*Jail list://' | tr -d '[:space:]' | tr ',' '\n'); do
          fail2ban-client set $jail unbanip {{ip}}
        done
      register: deban_result

    - name: Show result on unban
      ansible.builtin.debug:
        msg: "{{deban_result.stdout_lines}}"
