<commit_before>---

# Tasks about Jenkins main configuration management

# Manage deployment user configuration, without key for the first use
- name: 'Manage deployment user configuration without using private key'
  become: True
  become_user: "{{ jenkins_etc_user }}"
  manage_jenkins_users_and_security:
    user: "{{ item }}"
    security_realm: "{{ jenkins_security_realm }}"
    authorization_strategy: "{{ jenkins_authorization_strategy }}"
    crumb_issuer: "{{ jenkins_crumb.issuer }}"
    crumb_exclude_client_ip: "{{ jenkins_crumb.exclude_client_ip }}"
    use_private_key: False
    cli_path: "{{ jenkins_cli_path }}"
    deployment_ssh_key: "{{ jenkins_deployment_ssh_key }}"
    groovy_scripts_path: "{{ jenkins_groovy_scripts_path }}"
    url: "{{ jenkins_base_url }}"
  no_log: True
  register: 'jenkins_change_deployment_user_without_ssh_key'
  ignore_errors: True
  with_items:
    - username: "{{ jenkins_deployment_user.username }}"
      full_name: "{{ jenkins_deployment_user.full_name }}"
      email: "{{ jenkins_deployment_user.email }}"
      password: "{{ <PASSWORD> }}"
      roles:
        - 'jenkins-administer'
      public_keys:
        - "{{ jenkins_user_ssh_public_key.stdout }}"
  when: "jenkins_manage_users_and_security"


- name: 'Manage deployment user configuration using private key'
  become: True
  become_user: "{{ jenkins_etc_user }}"
  manage_jenkins_users_and_security:
    user: "{{ item }}"
    security_realm: "{{ jenkins_security_realm }}"
    authorization_strategy: "{{ jenkins_authorization_strategy }}"
    crumb_issuer: "{{ jenkins_crumb.issuer }}"
    crumb_exclude_client_ip: "{{ jenkins_crumb.exclude_client_ip }}"
    cli_path: "{{ jenkins_cli_path }}"
    deployment_ssh_key: "{{ jenkins_deployment_ssh_key }}"
    groovy_scripts_path: "{{ jenkins_groovy_scripts_path }}"
    url: "{{ jenkins_base_url }}"
  no_log: True
  register: 'jenkins_change_deployment_user'
  with_items:
    - username: "{{ jenkins_deployment_user.username }}"
      full_name: "{{ jenkins_deployment_user.full_name }}"
      email: "{{ jenkins_deployment_user.email }}"
      password: "{{ <PASSWORD> }}"
      roles:
        - 'jenkins-administer'
      public_keys:
        - "{{ jenkins_user_ssh_public_key.stdout }}"
  when:
    - "jenkins_manage_users_and_security"
    - "jenkins_change_deployment_user_without_ssh_key | failed"


- name: 'Check if deployment user config file exists'<commit_msg>Ensure Jenkins deployment user config folder exists<commit_after>---

# Tasks about Jenkins main configuration management

# Manage deployment user configuration, without key for the first use
- name: 'Manage deployment user configuration without using private key'
  become: True
  become_user: "{{ jenkins_etc_user }}"
  manage_jenkins_users_and_security:
    user: "{{ item }}"
    security_realm: "{{ jenkins_security_realm }}"
    authorization_strategy: "{{ jenkins_authorization_strategy }}"
    crumb_issuer: "{{ jenkins_crumb.issuer }}"
    crumb_exclude_client_ip: "{{ jenkins_crumb.exclude_client_ip }}"
    use_private_key: False
    cli_path: "{{ jenkins_cli_path }}"
    deployment_ssh_key: "{{ jenkins_deployment_ssh_key }}"
    groovy_scripts_path: "{{ jenkins_groovy_scripts_path }}"
    url: "{{ jenkins_base_url }}"
  no_log: True
  register: 'jenkins_change_deployment_user_without_ssh_key'
  ignore_errors: True
  with_items:
    - username: "{{ jenkins_deployment_user.username }}"
      full_name: "{{ jenkins_deployment_user.full_name }}"
      email: "{{ jenkins_deployment_user.email }}"
      password: "{{ <PASSWORD> }}"
      roles:
        - 'jenkins-administer'
      public_keys:
        - "{{ jenkins_user_ssh_public_key.stdout }}"
  when: "jenkins_manage_users_and_security"


- name: 'Manage deployment user configuration using private key'
  become: True
  become_user: "{{ jenkins_etc_user }}"
  manage_jenkins_users_and_security:
    user: "{{ item }}"
    security_realm: "{{ jenkins_security_realm }}"
    authorization_strategy: "{{ jenkins_authorization_strategy }}"
    crumb_issuer: "{{ jenkins_crumb.issuer }}"
    crumb_exclude_client_ip: "{{ jenkins_crumb.exclude_client_ip }}"
    cli_path: "{{ jenkins_cli_path }}"
    deployment_ssh_key: "{{ jenkins_deployment_ssh_key }}"
    groovy_scripts_path: "{{ jenkins_groovy_scripts_path }}"
    url: "{{ jenkins_base_url }}"
  no_log: True
  register: 'jenkins_change_deployment_user'
  with_items:
    - username: "{{ jenkins_deployment_user.username }}"
      full_name: "{{ jenkins_deployment_user.full_name }}"
      email: "{{ jenkins_deployment_user.email }}"
      password: "{{ <PASSWORD> }}"
      roles:
        - 'jenkins-administer'
      public_keys:
        - "{{ jenkins_user_ssh_public_key.stdout }}"
  when:
    - "jenkins_manage_users_and_security"
    - "jenkins_change_deployment_user_without_ssh_key | failed"


- name: 'Ensure Jenkins deployment user configuration folder exists'
  become: True
  file:
    path: "{{ item }}"
    owner: 'jenkins'
    group: 'jenkins'
    mode: '0644'
    state: 'directory'
  with_items:
    - "{{ jenkins_etc_home_location }}/users"
    - "{{ jenkins_etc_home_location }}/users/{{ jenkins_deployment_user.username }}"


- name: 'Check if deployment user config file exists'
{'fraction_non_alphanumeric': 0.11854103343465046, 'fraction_numerical': 0.0007598784194528875, 'mean_word_length': 4.312815338042381, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6932785', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1851, 'n_words': 296}