<commit_before>---
  # Parameters:
  #  ssh_current_user: Current deployment user where we look for ssh keys to copy (provided)
  #  user: new user name to be created (provided)
  #  group: new user group to be created (provided)
  #  home: new user home to be created
  #
  # Example usage:
  #  - include: "{{prudentia_dir}}/tasks/sudo-user.yml user=prudentia group=prudentia home=/home/prudentia ssh_current_user=root"

  - debug: msg="Creating sudo user {{user}}:{{group}} with home directory {{home}}"
    tags: sudoer

    # The creation of a sudo user is generally executed just after creating an instance
    # so we wait for the SSH port to become available and we start checking after a little delay
  - name: Sudo User | Wait for SSH
    local_action: wait_for host={{inventory_hostname}} port=22 delay=5 timeout=60
    tags: sudoer

  - name: Sudo User | Creating group
    group: name={{group}} state=present
    tags: sudoer

  - name: Sudo User | Creating user
    user: name={{user}} group={{group}} home={{home}} comment={{user}} state=present shell=/bin/bash generate_ssh_key=yes groups=sudo
    tags: sudoer

  - name: Sudo User | Check key presence
    stat: path=~{{ssh_current_user}}/.ssh/authorized_keys
    register: check_authorized_keys

  - name: Sudo User | Copy authorized_keys from root
    command: cp ~{{ssh_current_user}}/.ssh/authorized_keys {{home}}/.ssh/authorized_keys
    when: check_authorized_keys.stat.exists
    tags: sudoer

  - name: Sudo User | Set permission on authorized_keys
    file: path={{home}}/.ssh/authorized_keys mode=600 owner={{user}} group={{group}}
    when: check_authorized_keys.stat.exists
    tags: sudoer

  - name: Sudo User | Ensuring sudoers no pwd prompting
    lineinfile: dest=/etc/sudoers state=present regexp="%{{user}}" line="%{{user}} ALL=(ALL) NOPASSWD:ALL" validate="visudo -cf %s"
    tags: sudoer<commit_msg>feature(add_sudo_user): Rewrite ssh check<commit_after>---
  # Parameters:
  #  ssh_current_user: Current deployment user where we look for ssh keys to copy (provided)
  #  user: new user name to be created (provided)
  #  group: new user group to be created (provided)
  #  home: new user home to be created
  #
  # Example usage:
  #  - include: "{{prudentia_dir}}/tasks/sudo-user.yml user=prudentia group=prudentia home=/home/prudentia ssh_current_user=root"

  - debug: msg="Creating sudo user {{user}}:{{group}} with home directory {{home}}"
    tags: sudoer

    # The creation of a sudo user is generally executed just after creating an instance
    # so we wait for the SSH port to become available and we start checking after a little delay
  - name: Sudo User | Wait for SSH
    wait_for: port=22 search_regex=OpenSSH delay=5 timeout=60
    tags: sudoer

  - name: Sudo User | Creating group
    group: name={{group}} state=present
    tags: sudoer

  - name: Sudo User | Creating user
    user: name={{user}} group={{group}} home={{home}} comment={{user}} state=present shell=/bin/bash generate_ssh_key=yes groups=sudo
    tags: sudoer

  - name: Sudo User | Check key presence
    stat: path=~{{ssh_current_user}}/.ssh/authorized_keys
    register: check_authorized_keys

  - name: Sudo User | Copy authorized_keys from root
    command: cp ~{{ssh_current_user}}/.ssh/authorized_keys {{home}}/.ssh/authorized_keys
    when: check_authorized_keys.stat.exists
    tags: sudoer

  - name: Sudo User | Set permission on authorized_keys
    file: path={{home}}/.ssh/authorized_keys mode=600 owner={{user}} group={{group}}
    when: check_authorized_keys.stat.exists
    tags: sudoer

  - name: Sudo User | Ensuring sudoers no pwd prompting
    lineinfile: dest=/etc/sudoers state=present regexp="%{{user}}" line="%{{user}} ALL=(ALL) NOPASSWD:ALL" validate="visudo -cf %s"
    tags: sudoer
{'fraction_non_alphanumeric': 0.11501850872554203, 'fraction_numerical': 0.004230565838180857, 'mean_word_length': 4.0239043824701195, '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': '2956012', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1154, 'n_words': 381}