<commit_before>---

#Copyright 2016 ShapeBlue
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

- name: gather OS facts
  os_facts:

#- name: Set hostname pt1
#  hostname:
#    name: "{{ inventory_hostname }}"
#    when: ansible_distribution_major_version|int != 20

- name: Set hostname pt2
  shell: "hostnamectl set-hostname {{ inventory_hostname }}"

- name: set apt repo
  template:
    src: "{{ inventory_dir }}/templates/{{ item }}-u18.j2"
    dest: "/etc/apt/{{item}}"
  with_items:
    - "sources.list"
  when: ansible_distribution_version|version_compare('18.04','==')

- apt_key:
    url: "{{ repohost }}/release.asc"
    state: present

- apt_key:
    keyserver: keyserver.ubuntu.com
    id: 86F44E2A

- name: Add openjdk-ppa repository into sources list.
  apt_repository:
    repo: "ppa:webupd8team/java"
    state: present
  when: ansible_distribution_major_version|int < 20

- name: Run the equivalent of "apt-get update" as a separate step
  apt:
    update_cache: yes

- name: Install basic utilities and tools - all OS versions
  apt:
    pkg: "{{ item }}"
    state: latest
    update_cache: yes
  with_items:
    - openssh-client
    - telnet
    - tcpdump
    - qemu-kvm
    - parted

- name: Install basic utilities and tools - pre bionic
  apt:
    pkg: "{{ item }}"
    state: latest
    update_cache: yes
  with_items:
    - openntpd
    - traceroute
    - iptables-persistent
  when: ansible_distribution_version|version_compare('18.04','<')

- set_fact: java_ver="{{ kvm_java_ver }}"
- set_fact: java_path="{{ kvm_java_path }}"

- debug: msg="Java version required is {{ java_ver }}"

- name: Ensure correct open-jdk is installed
  apt:
    pkg: "{{ kvm_java_path }}"
    state: latest
    update_cache: yes

- include: ./add_local_storage.yml
  when: use_local_storage
  tags:
    - kvm

- name: workaround ssh crypo issues
  lineinfile:
    path: /etc/ssh/sshd_config
    line: "{{ item }}"
  with_items:
    - "PubkeyAcceptedKeyTypes=+ssh-dss"
    - "HostKeyAlgorithms=+ssh-dss"
    - "KexAlgorithms=+diffie-hellman-group1-sha1"
  tags:
    - kvm
  when: ansible_distribution_version|version_compare('20.04','<=')

- name: Restart sshd
  systemd:
    name: sshd
    state: restarted
  when: ansible_distribution_version|version_compare('20.04','<=')
  tags:
    - kvm


- name: Wait for SSH
  local_action: wait_for port=22 host="{{ ansible_ssh_host }}" timeout={{ ssh_retries }} connect_timeout=5
  when: ansible_distribution_version|version_compare('20.04','<=')
  tags:
    - kvm
  delegate_to: localhost

- name: Added network instances file to precise/trusty/xenial
  template: src=interfaces.j2 dest="/etc/network/interfaces"
  when: ansible_distribution_version|version_compare('16.04','<=') and kvm_network_mode == "bridge"

## start block

- name: netplan on Ubuntu 18 onwards
  block:
 
  - name: write netplan<commit_msg>add java 11 repo for ubuntu 16<commit_after>---

#Copyright 2016 ShapeBlue
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

- name: gather OS facts
  os_facts:

#- name: Set hostname pt1
#  hostname:
#    name: "{{ inventory_hostname }}"
#    when: ansible_distribution_major_version|int != 20

- name: Set hostname pt2
  shell: "hostnamectl set-hostname {{ inventory_hostname }}"

- name: set apt repo
  template:
    src: "{{ inventory_dir }}/templates/{{ item }}-u18.j2"
    dest: "/etc/apt/{{item}}"
  with_items:
    - "sources.list"
  when: ansible_distribution_version|version_compare('18.04','==')

- apt_key:
    url: "{{ repohost }}/release.asc"
    state: present

- apt_key:
    keyserver: keyserver.ubuntu.com
    id: 86F44E2A

- name: Add openjdk-ppa repository into sources list.
  apt_repository:
    repo: "ppa:webupd8team/java"
    state: present
  when: ansible_distribution_major_version|int < 20

- name: Add openjdk-ppa repository into sources list.
  apt_repository:
    repo: "ppa:openjdk-r/ppa"
    state: present
  when: ansible_distribution_major_version|int = 16

- name: Run the equivalent of "apt-get update" as a separate step
  apt:
    update_cache: yes

- name: Install basic utilities and tools - all OS versions
  apt:
    pkg: "{{ item }}"
    state: latest
    update_cache: yes
  with_items:
    - openssh-client
    - telnet
    - tcpdump
    - qemu-kvm
    - parted

- name: Install basic utilities and tools - pre bionic
  apt:
    pkg: "{{ item }}"
    state: latest
    update_cache: yes
  with_items:
    - openntpd
    - traceroute
    - iptables-persistent
  when: ansible_distribution_version|version_compare('18.04','<')

- set_fact: java_ver="{{ kvm_java_ver }}"
- set_fact: java_path="{{ kvm_java_path }}"

- debug: msg="Java version required is {{ java_ver }}"

- name: Ensure correct open-jdk is installed
  apt:
    pkg: "{{ kvm_java_path }}"
    state: latest
    update_cache: yes

- include: ./add_local_storage.yml
  when: use_local_storage
  tags:
    - kvm

- name: workaround ssh crypo issues
  lineinfile:
    path: /etc/ssh/sshd_config
    line: "{{ item }}"
  with_items:
    - "PubkeyAcceptedKeyTypes=+ssh-dss"
    - "HostKeyAlgorithms=+ssh-dss"
    - "KexAlgorithms=+diffie-hellman-group1-sha1"
  tags:
    - kvm
  when: ansible_distribution_version|version_compare('20.04','<=')

- name: Restart sshd
  systemd:
    name: sshd
    state: restarted
  when: ansible_distribution_version|version_compare('20.04','<=')
  tags:
    - kvm

- name: Wait for SSH
  local_action: wait_for port=22 host="{{ ansible_ssh_host }}" timeout={{ ssh_retries }} connect_timeout=5
  when: ansible_distribution_version|version_compare('20.04','<=')
  tags:
    - kvm
  delegate_to: localhost

- name: Added network instances file to precise/trusty/xenial
  template: src=interfaces.j2 dest="/etc/network/interfaces"
  when: ansible_distribution_version|version_compare('16.04','<=') and kvm_network_mode == "bridge"

## start block

- name: netplan on Ubuntu 18 onwards
  block:
 
  - name: write netplan
{'fraction_non_alphanumeric': 0.11596516690856314, 'fraction_numerical': 0.01683599419448476, 'mean_word_length': 3.6217303822937628, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1988542', 'n_tokens_mistral': 2450, 'n_tokens_neox': 2298, 'n_words': 640}