From cd7381d8de3258c0cfc2a7e77957fa8ab267f955 Mon Sep 17 00:00:00 2001
From: Kenichi Omichi <ken1ohmichi@gmail.com>
Date: Thu, 9 Jun 2022 07:07:42 -0700
Subject: [PATCH] Drop Ansible support for v2.9 and v2.10 (#8925)

Ansible v2.9 and v2.10 are EOL as [1].
This drops those version supports by following the upstream Ansible.

This sets use_ssh_args true always because that is required to use
ssh_args on ansible.cfg on Ansible v2.11 or later[2].

ansible_ssh_host is replaced with ansible_host because ansible_ssh_host
has been deprecated already and cenots7 jobs were failed due to the
deprecated ansible_ssh_host.

[1]: https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html#ansible-core-changelogs
[2]: https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html#parameter-use_ssh_args
---
 .gitlab-ci.yml                                     |  2 +-
 README.md                                          |  2 +-
 ansible.cfg                                        |  2 +-
 ansible_version.yml                                | 14 +-------------
 docs/ansible.md                                    |  2 --
 requirements-2.10.txt                              | 10 ----------
 requirements-2.9.txt                               | 10 ----------
 requirements-2.9.yml                               |  4 ----
 roles/download/tasks/download_container.yml        |  4 ++--
 roles/download/tasks/download_file.yml             |  4 ++--
 .../roles/packet-ci/templates/inventory.j2         |  2 +-
 tests/cloud_playbooks/wait-for-ssh.yml             |  2 +-
 tests/requirements-2.10.txt                        | 11 -----------
 tests/requirements-2.9.txt                         | 14 --------------
 14 files changed, 10 insertions(+), 73 deletions(-)
 delete mode 100644 requirements-2.10.txt
 delete mode 100644 requirements-2.9.txt
 delete mode 100644 requirements-2.9.yml
 delete mode 100644 tests/requirements-2.10.txt
 delete mode 100644 tests/requirements-2.9.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fac73650a..65ecd3c96 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -34,7 +34,7 @@ variables:
   RECOVER_CONTROL_PLANE_TEST: "false"
   RECOVER_CONTROL_PLANE_TEST_GROUPS: "etcd[2:],kube_control_plane[1:]"
   TERRAFORM_VERSION: 1.0.8
-  ANSIBLE_MAJOR_VERSION: "2.10"
+  ANSIBLE_MAJOR_VERSION: "2.11"
 
 before_script:
   - ./tests/scripts/rebase.sh
diff --git a/README.md b/README.md
index c7112f759..05d497590 100644
--- a/README.md
+++ b/README.md
@@ -163,7 +163,7 @@ Note: Upstart/SysV init based OS types are not supported.
 ## Requirements
 
 - **Minimum required version of Kubernetes is v1.21**
-- **Ansible v2.9.x, Jinja 2.11+ and python-netaddr is installed on the machine that will run Ansible commands**
+- **Ansible v2.11+, Jinja 2.11+ and python-netaddr is installed on the machine that will run Ansible commands**
 - The target servers must have **access to the Internet** in order to pull docker images. Otherwise, additional configuration is required (See [Offline Environment](docs/offline-environment.md))
 - The target servers are configured to allow **IPv4 forwarding**.
 - If using IPv6 for pods and services, the target servers are configured to allow **IPv6 forwarding**.
diff --git a/ansible.cfg b/ansible.cfg
index 79c2bc56c..cec8bcec9 100644
--- a/ansible.cfg
+++ b/ansible.cfg
@@ -1,6 +1,6 @@
 [ssh_connection]
 pipelining=True
-ssh_args = -o ControlMaster=auto -o ControlPersist=30m -o ConnectionAttempts=100 -o UserKnownHostsFile=/dev/null
+ansible_ssh_args = -o ControlMaster=auto -o ControlPersist=30m -o ConnectionAttempts=100 -o UserKnownHostsFile=/dev/null
 #control_path = ~/.ssh/ansible-%%r@%%h:%%p
 [defaults]
 # https://github.com/ansible/ansible/issues/56930 (to ignore group names with - and .)
diff --git a/ansible_version.yml b/ansible_version.yml
index 755947e06..744868304 100644
--- a/ansible_version.yml
+++ b/ansible_version.yml
@@ -3,8 +3,7 @@
   gather_facts: false
   become: no
   vars:
-    minimal_ansible_version: 2.9.0
-    minimal_ansible_version_2_10: 2.10.11
+    minimal_ansible_version: 2.11.0
     maximal_ansible_version: 2.13.0
     ansible_connection: local
   tags: always
@@ -18,17 +17,6 @@
       tags:
         - check
 
-    - name: "Check Ansible version > {{ minimal_ansible_version_2_10 }} when using ansible 2.10"
-      assert:
-        msg: "When using Ansible 2.10, the minimum supported version is {{ minimal_ansible_version_2_10 }}"
-        that:
-          - ansible_version.string is version(minimal_ansible_version_2_10, ">=")
-          - ansible_version.string is version(maximal_ansible_version, "<")
-      when:
-        - ansible_version.string is version('2.10.0', ">=")
-      tags:
-        - check
-
     - name: "Check that python netaddr is installed"
       assert:
         msg: "Python netaddr is not present"
diff --git a/docs/ansible.md b/docs/ansible.md
index 972d5f826..7d48a7fdf 100644
--- a/docs/ansible.md
+++ b/docs/ansible.md
@@ -26,8 +26,6 @@ Based on the table below and the available python version for your ansible host
 
 | Ansible Version | Python Version |
 | --------------- | -------------- |
-| 2.9             | 2.7,3.5-3.8    |
-| 2.10            | 2.7,3.5-3.8    |
 | 2.11            | 2.7,3.5-3.9    |
 | 2.12            | 3.8-3.10       |
 
diff --git a/requirements-2.10.txt b/requirements-2.10.txt
deleted file mode 100644
index a320942a7..000000000
--- a/requirements-2.10.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-ansible==3.4.0
-ansible-base==2.10.15
-cryptography==2.8
-jinja2==2.11.3
-netaddr==0.7.19
-pbr==5.4.4
-jmespath==0.9.5
-ruamel.yaml==0.16.10
-ruamel.yaml.clib==0.2.6
-MarkupSafe==1.1.1
diff --git a/requirements-2.9.txt b/requirements-2.9.txt
deleted file mode 100644
index 8fe4a552d..000000000
--- a/requirements-2.9.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-ansible==2.9.27
-cryptography==2.8
-jinja2==2.11.3
-netaddr==0.7.19
-pbr==5.4.4
-jmespath==0.9.5
-ruamel.yaml==0.16.10
-ruamel.yaml.clib==0.2.6 ; python_version >= '3.5'
-ruamel.yaml.clib==0.2.2 ; python_version < '3.5'
-MarkupSafe==1.1.1
diff --git a/requirements-2.9.yml b/requirements-2.9.yml
deleted file mode 100644
index e8034543d..000000000
--- a/requirements-2.9.yml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-collections:
-- name: community.general
-  version: '<3.0'
diff --git a/roles/download/tasks/download_container.yml b/roles/download/tasks/download_container.yml
index 95267578f..41790fe15 100644
--- a/roles/download/tasks/download_container.yml
+++ b/roles/download/tasks/download_container.yml
@@ -83,7 +83,7 @@
       synchronize:
         src: "{{ image_path_final }}"
         dest: "{{ image_path_cached }}"
-        use_ssh_args: "{{ has_bastion | default(false) }}"
+        use_ssh_args: true
         mode: pull
       when:
         - not image_is_cached
@@ -95,7 +95,7 @@
       synchronize:
         src: "{{ image_path_cached }}"
         dest: "{{ image_path_final }}"
-        use_ssh_args: "{{ has_bastion | default(false) }}"
+        use_ssh_args: true
         mode: push
       delegate_facts: no
       register: upload_image
diff --git a/roles/download/tasks/download_file.yml b/roles/download/tasks/download_file.yml
index d84098648..2e054eff5 100644
--- a/roles/download/tasks/download_file.yml
+++ b/roles/download/tasks/download_file.yml
@@ -103,7 +103,7 @@
     synchronize:
       src: "{{ file_path_cached }}"
       dest: "{{ file_path_cached }}"
-      use_ssh_args: "{{ has_bastion | default(false) }}"
+      use_ssh_args: true
       mode: pull
     when:
     - download_force_cache
@@ -114,7 +114,7 @@
     synchronize:
       src: "{{ file_path_cached }}"
       dest: "{{ download.dest }}"
-      use_ssh_args: "{{ has_bastion | default(false) }}"
+      use_ssh_args: true
       mode: push
     register: get_task
     until: get_task is succeeded
diff --git a/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2 b/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2
index f8f76d08e..c49d582f4 100644
--- a/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2
+++ b/tests/cloud_playbooks/roles/packet-ci/templates/inventory.j2
@@ -1,6 +1,6 @@
 [all]
 {% for instance in vms.results %}
-instance-{{ loop.index }} ansible_ssh_host={{instance.stdout}}
+instance-{{ loop.index }} ansible_host={{instance.stdout}}
 {% endfor %}
 
 {% if mode is defined and mode in ["separate", "separate-scale"] %}
diff --git a/tests/cloud_playbooks/wait-for-ssh.yml b/tests/cloud_playbooks/wait-for-ssh.yml
index 417a541f4..7c439d9a1 100644
--- a/tests/cloud_playbooks/wait-for-ssh.yml
+++ b/tests/cloud_playbooks/wait-for-ssh.yml
@@ -6,7 +6,7 @@
   tasks:
   - name: Wait until SSH is available
     wait_for:
-      host: "{{ ansible_ssh_host }}"
+      host: "{{ ansible_host }}"
       port: 22
       timeout: 240
     delegate_to: localhost
diff --git a/tests/requirements-2.10.txt b/tests/requirements-2.10.txt
deleted file mode 100644
index 0d0cd6565..000000000
--- a/tests/requirements-2.10.txt
+++ /dev/null
@@ -1,11 +0,0 @@
--r ../requirements-2.10.txt
-yamllint==1.19.0
-apache-libcloud==2.2.1
-tox==3.11.1
-dopy==0.3.7
-ansible-lint==5.4.0
-molecule==3.0.6
-molecule-vagrant==0.3
-testinfra==5.2.2
-python-vagrant==0.5.15
-ara[server]==1.5.7
diff --git a/tests/requirements-2.9.txt b/tests/requirements-2.9.txt
deleted file mode 100644
index aca01027c..000000000
--- a/tests/requirements-2.9.txt
+++ /dev/null
@@ -1,14 +0,0 @@
--r ../requirements-2.9.txt
-yamllint==1.19.0
-apache-libcloud==2.2.1
-tox==3.11.1
-dopy==0.3.7
-ansible-lint==5.4.0 ; python_version >= '3.0'
-ansible-lint==4.2.0 ; python_version < '3.0'
-molecule==3.0.6 ; python_version >= '3.0'
-molecule==3.0.2 ; python_version < '3.0'
-molecule-vagrant==0.3
-testinfra==5.2.2 ; python_version >= '3.0'
-testinfra==3.4.0 ; python_version < '3.0'
-python-vagrant==0.5.15
-ara[server]==1.5.7
-- 
GitLab