<commit_before># -*- eval: (ansible) -*-
- include: vault.yml load=ldap hosts=ldap.hashbang.sh

- name: Parse parameters
  hosts: ldap.hashbang.sh,shell_servers
  gather_facts: no

  vars_prompt:
    - name: users
      prompt: Comma-separated list of users to ban
      private: no

    - name: delete
      prompt: Delete home directories? (yes/no)
      private: no
      default: "no"

  tasks:
    - name: Parse users list
      set_fact:
        user_list: "{{ users.split(',') }}"
        delete_homedirs: "{{ delete }}"

- name: Disable the account in LDAP
  hosts: ldap.hashbang.sh
  gather_facts: no
  tasks:
    - ldap_attr:
        server_uri: ldaps://ldap.hashbang.sh
        bind_dn: "{{ ldap.admin.dn }}"
        bind_pw: "{{ ldap.admin.password }}"

        dn: uid={{ item }},ou=People,dc=hashbang,dc=sh
        name: loginShell
        state: exact
        values: /usr/sbin/nologin
      delegate_to: localhost
      with_items: "{{ user_list }}"

- hosts: shell_servers
  become: true
  gather_facts: no
  tasks:
    - name: Invalidate SSSd cache entries
      command: sss_cache -u {{ item }}
      with_items: "{{ user_list }}"
      changed_when: false
      ignore_errors: yes

    - name: Terminate user sessions
      command: loginctl terminate-user {{ item }}
      register: terminate
      with_items: "{{ user_list }}"
      failed_when: |
        'Could not terminate user: No user' not in terminate.stderr
        and terminate|failed
      changed_when: terminate.stderr == "" and terminate|success

    - name: Delete home directories
      when: delete_homedirs
      with_items: "{{ user_list }}"
      file:
        path: /home/{{ item }}
        state: absent<commit_msg>ldap_ban: Minox fixup (use `is failed` in `failed_when`)<commit_after># -*- eval: (ansible) -*-
- include: vault.yml load=ldap hosts=ldap.hashbang.sh

- name: Parse parameters
  hosts: ldap.hashbang.sh,shell_servers
  gather_facts: no

  vars_prompt:
    - name: users
      prompt: Comma-separated list of users to ban
      private: no

    - name: delete
      prompt: Delete home directories? (yes/no)
      private: no
      default: "no"

  tasks:
    - name: Parse users list
      set_fact:
        user_list: "{{ users.split(',') }}"
        delete_homedirs: "{{ delete }}"

- name: Disable the account in LDAP
  hosts: ldap.hashbang.sh
  gather_facts: no
  tasks:
    - ldap_attr:
        server_uri: ldaps://ldap.hashbang.sh
        bind_dn: "{{ ldap.admin.dn }}"
        bind_pw: "{{ ldap.admin.password }}"

        dn: uid={{ item }},ou=People,dc=hashbang,dc=sh
        name: loginShell
        state: exact
        values: /usr/sbin/nologin
      delegate_to: localhost
      with_items: "{{ user_list }}"

- hosts: shell_servers
  become: true
  gather_facts: no
  tasks:
    - name: Invalidate SSSd cache entries
      command: sss_cache -u {{ item }}
      with_items: "{{ user_list }}"
      changed_when: false
      ignore_errors: yes

    - name: Terminate user sessions
      command: loginctl terminate-user {{ item }}
      register: terminate
      with_items: "{{ user_list }}"
      failed_when: |
        'Could not terminate user: No user' not in terminate.stderr
        and terminate is failed
      changed_when: terminate.stderr == "" and terminate|success

    - name: Delete home directories
      when: delete_homedirs
      with_items: "{{ user_list }}"
      file:
        path: /home/{{ item }}
        state: absent
{'fraction_non_alphanumeric': 0.11598384304673975, 'fraction_numerical': 0.0, 'mean_word_length': 2.4191321499013805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2674935', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1120, 'n_words': 294}