<commit_before>---
# roles/ssh-config/tasks/main.yml

- name: Ensure the hostname entry for master is available for the client.
  lineinfile:
    dest: /etc/hosts
    regexp: "{{ mysql_repl_master }}"
    line: "{{ hostvars[mysql_repl_master].public_ipv4_address + ' ' + mysql_repl_master }}"
    state: present
  when: mysql_repl_role == 'slave' and mysql_repl_master is defined
  tags:
    - mysql
    - repl

- name: Ensure the hostname entry for the slave is entered into hosts file
  lineinfile:
    dest: /etc/hosts
    regexp: "{{ mysql_repl_slave }}"
    line: "{{ hostvars[mysql_repl_slave].public_ipv4_address + ' ' + mysql_repl_slave }}"
    state: present
  when: mysql_repl_role == 'master' and mysql_repl_slave is defined
  tags:
    - mysql
    - repl

- name: Generating RSA key for root
  user:
    name: root
    generate_ssh_key: yes
  tags:
    - ssh_config
    - ssh_pub_key

- name: Downloading generated SSH public keys
  fetch:
    src: /root/.ssh/id_rsa.pub
    dest: "/tmp/id_rsa_{{ inventory_hostname }}.pub"
    flat: yes
  tags:
    - ssh_config
    - ssh_pub_key

- name: Copying slave's ssh key to master
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/tmp/id_rsa_' + mysql_repl_slave + '.pub') }}"
  when: mysql_repl_role == 'master' and mysql_repl_slave is defined
  tags:
    - ssh_config
    - ssh_pub_key

- name: Copying master's ssh key to slave
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/tmp/id_rsa_' + mysql_repl_master + '.pub') }}"
  when: mysql_repl_role == 'slave' and mysql_repl_master is defined
  tags:
    - ssh_config
    - ssh_pub_key

- name: Make sure the known hosts file exists
  file:
    path: "{{ ssh_known_hosts_file }}"
    state: touch
  tags:
    - ssh_config
    - ssh_known_hosts

- name: Scan the public key slave
  shell: "{{ ssh_known_hosts_command }} {{ mysql_repl_master }} >> {{ ssh_known_hosts_file }}"
  when: mysql_repl_role == 'slave' and mysql_repl_master is defined
  tags:
    - ssh_config
    - ssh_known_hosts

- name: Scan the public key master
  shell: "{{ ssh_known_hosts_command }} {{ item }} >> {{ ssh_known_hosts_file }}"
  loop:
    - "{{mysql_repl_slave}}"
  when: mysql_repl_role == 'master' and mysql_repl_slave is defined
  tags:
    - ssh_config
    - ssh_known_hosts<commit_msg>Make sure variable are defined before checking<commit_after>---
# roles/ssh-config/tasks/main.yml

- name: Ensure the hostname entry for master is available for the client.
  lineinfile:
    dest: /etc/hosts
    regexp: "{{ mysql_repl_master }}"
    line: "{{ hostvars[mysql_repl_master].public_ipv4_address + ' ' + mysql_repl_master }}"
    state: present
  when: mysql_repl_role is defined and
        mysql_repl_role == 'slave' and
        mysql_repl_master is defined
  tags:
    - mysql
    - repl

- name: Ensure the hostname entry for the slave is entered into hosts file
  lineinfile:
    dest: /etc/hosts
    regexp: "{{ mysql_repl_slave }}"
    line: "{{ hostvars[mysql_repl_slave].public_ipv4_address + ' ' + mysql_repl_slave }}"
    state: present
  when: mysql_repl_role is defined and
        mysql_repl_role == 'master' and
        mysql_repl_slave is defined
  tags:
    - mysql
    - repl

- name: Generating RSA key for root
  user:
    name: root
    generate_ssh_key: yes
  tags:
    - ssh_config
    - ssh_pub_key

- name: Downloading generated SSH public keys
  fetch:
    src: /root/.ssh/id_rsa.pub
    dest: "/tmp/id_rsa_{{ inventory_hostname }}.pub"
    flat: yes
  tags:
    - ssh_config
    - ssh_pub_key

- name: Copying slave's ssh key to master
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/tmp/id_rsa_' + mysql_repl_slave + '.pub') }}"
  when: mysql_repl_role is defined and
        mysql_repl_role == 'master' and
        mysql_repl_slave is defined
  tags:
    - ssh_config
    - ssh_pub_key

- name: Copying master's ssh key to slave
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/tmp/id_rsa_' + mysql_repl_master + '.pub') }}"
  when: mysql_repl_role is defined and
        mysql_repl_role == 'slave' and
        mysql_repl_master is defined
  tags:
    - ssh_config
    - ssh_pub_key

- name: Make sure the known hosts file exists
  file:
    path: "{{ ssh_known_hosts_file }}"
    state: touch
  tags:
    - ssh_config
    - ssh_known_hosts

- name: Scan the public key slave
  shell: "{{ ssh_known_hosts_command }} {{ mysql_repl_master }} >> {{ ssh_known_hosts_file }}"
  when: mysql_repl_role is defined and
        mysql_repl_role == 'slave' and
        mysql_repl_master is defined
  tags:
    - ssh_config
    - ssh_known_hosts

- name: Scan the public key master
  shell: "{{ ssh_known_hosts_command }} {{ item }} >> {{ ssh_known_hosts_file }}"
  loop:
    - "{{mysql_repl_slave}}"
  when: mysql_repl_role is defined and
        mysql_repl_role == 'master' and
        mysql_repl_slave is defined
  tags:
    - ssh_config
    - ssh_known_hosts
{'fraction_non_alphanumeric': 0.10482096419283857, 'fraction_numerical': 0.0008001600320064013, 'mean_word_length': 3.0032025620496396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4309440', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1736, 'n_words': 451}