Jelajahi Sumber

Merge init playbooks into openshift_node

Jeremiah Stuever 6 tahun lalu
induk
melakukan
b3f59cc40d

+ 0 - 46
playbooks/init/base_packages.yml

@@ -1,46 +0,0 @@
----
-# l_base_packages_hosts may be passed in via prerequisites.yml during scaleup plays
-# and upgrade_control_plane.yml upgrade plays.
-
-- name: Install packages necessary for installer
-  hosts: "{{ l_base_packages_hosts | default('oo_all_hosts') }}"
-  any_errors_fatal: true
-  tasks:
-  - name: Determine if chrony is installed
-    command: rpm -q chrony
-    failed_when: false
-    register: chrony_installed
-
-  - name: Install ntp package
-    package:
-      name: ntp
-      state: present
-    when:
-    - openshift_clock_enabled | default(True) | bool
-    - chrony_installed.rc != 0
-    register: result
-    until: result is succeeded
-
-  - name: Start and enable ntpd/chronyd
-    command: timedatectl set-ntp true
-    when: openshift_clock_enabled | default(True) | bool
-
-  - name: Ensure openshift-ansible installer package deps are installed
-    package:
-      name: "{{ pkg_list | join(',') }}"
-      state: present
-    vars:
-      pkg_list_temp:
-      - iproute
-      - "{{ 'python3-dbus' if ansible_distribution == 'Fedora' else 'dbus-python' }}"
-      - "{{ 'python3-PyYAML' if ansible_distribution == 'Fedora' else 'PyYAML' }}"
-      - libsemanage-python
-      - yum-utils
-      - "{{ 'python3-docker' if ansible_distribution == 'Fedora' else 'python-docker-py' }}"
-      - systemd-journal-gateway
-      pkg_list_non_fedora:
-      - 'python-ipaddress'
-      pkg_list_use_non_fedora: "{{ ansible_distribution != 'Fedora' | bool }}"
-      pkg_list: "{{ pkg_list_non_fedora | ternary(pkg_list_non_fedora, []) + pkg_list_temp }}"
-    register: result
-    until: result is succeeded

+ 0 - 96
playbooks/init/basic_facts.yml

@@ -1,96 +0,0 @@
----
-- name: Ensure that all non-node hosts are accessible
-  hosts: oo_masters_to_config:oo_etcd_to_config:oo_lb_to_config:oo_nfs_to_config
-  any_errors_fatal: true
-  tasks:
-
-- name: Initialize basic host facts
-  # l_init_fact_hosts is passed in via play during control-plane-only
-  # upgrades and scale-up plays; otherwise oo_all_hosts is used.
-  hosts: "{{ l_init_fact_hosts | default('oo_all_hosts') }}"
-  tasks:
-
-  - name: Detect OS Variant from /etc/os-release
-    fail:
-      msg: Atomic Host installations are no longer supported
-    when: lookup('ini', 'VARIANT_ID type=properties file=/etc/os-release') == 'atomic.host'
-
-  # TODO(michaelgugino) remove this line once CI is updated.
-  - name: set openshift_deployment_type if unset
-    set_fact:
-      openshift_deployment_type: "{{ deployment_type }}"
-      openshift_is_atomic: False
-    when:
-    - openshift_deployment_type is undefined
-    - deployment_type is defined
-
-- name: Read API URL from infra config
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}"
-  tasks:
-  - name: Read cluster config
-    k8s_facts:
-      kubeconfig: "{{ kubeconfig_path }}"
-      kind: Infrastructure
-      name: cluster
-    register: clustercfg
-    when: kubeconfig_path is defined
-    until:
-    - clustercfg.resources is defined
-    - clustercfg.resources | length > 0
-    - clustercfg.resources[0].status is defined
-    - clustercfg.resources[0].status.apiServerURL is defined
-    retries: 36
-    delay: 5
-    delegate_to: localhost
-  - name: Set fact openshift_api_prefix
-    set_fact:
-      openshift_api_prefix: "{{ clustercfg.resources[0].status.apiServerURL.split(':')[0:-1] | join(':') }}"
-
-- name: Set worker openshift_bootstrap_endpoint if not already defined
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}:!masters:!bootstrap"
-  tasks:
-  - set_fact:
-      openshift_bootstrap_endpoint: "{{ openshift_api_prefix }}:22623/config/worker"
-    when:
-    - kubeconfig_path is defined
-    - openshift_bootstrap_endpoint is not defined
-
-- name: Set master openshift_bootstrap_endpoint if not already defined
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}:&masters"
-  tasks:
-  - set_fact:
-      openshift_bootstrap_endpoint: "{{ openshift_api_prefix }}:22623/config/master"
-    when:
-    - kubeconfig_path is defined
-    - openshift_bootstrap_endpoint is not defined
-
-- name: Read in openshift-install
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}"
-  tasks:
-  - slurp:
-      src: "{{ openshift_install_config_path }}"
-    register: openshift_install_config_reg
-    delegate_to: localhost
-    when: openshift_install_config_path is defined
-  - name: 'set openshift_install_config if path is defined'
-    set_fact:
-      openshift_install_config: "{{ openshift_install_config_reg['content'] | b64decode | from_yaml }}"
-    when: openshift_install_config_path is defined
-
-- name: Set worker openshift_bootstrap_endpoint if not already defined
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}:!masters:!bootstrap"
-  tasks:
-  - set_fact:
-      openshift_bootstrap_endpoint: "https://api.{{ openshift_install_config['metadata']['name'] }}.{{ openshift_install_config['baseDomain'] }}:22623/config/worker"
-    when:
-    - openshift_install_config_path is defined
-    - openshift_bootstrap_endpoint is not defined
-
-- name: Set master openshift_bootstrap_endpoint if not already defined
-  hosts: "{{ l_init_fact_hosts | default('nodes') }}:&masters"
-  tasks:
-  - set_fact:
-      openshift_bootstrap_endpoint: "https://api.{{ openshift_install_config['metadata']['name'] }}.{{ openshift_install_config['baseDomain'] }}:22623/config/master"
-    when:
-    - openshift_install_config_path is defined
-    - openshift_bootstrap_endpoint is not defined

+ 0 - 138
playbooks/init/evaluate_groups.yml

@@ -1,138 +0,0 @@
----
-- name: Populate config host groups
-  hosts: localhost
-  connection: local
-  gather_facts: no
-  tasks:
-  - name: Load group name mapping variables
-    include_vars: vars/cluster_hosts.yml
-
-  - name: Evaluate groups - g_nfs_hosts is single host
-    fail:
-      msg: The nfs group must be limited to one host
-    when: g_nfs_hosts | length > 1
-
-  - name: Evaluate oo_all_hosts
-    add_host:
-      name: "{{ item }}"
-      groups: oo_all_hosts
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_all_hosts | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_masters
-    add_host:
-      name: "{{ item }}"
-      groups: oo_masters
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_first_master
-    add_host:
-      name: "{{ g_master_hosts[0] }}"
-      groups: oo_first_master
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    when: g_master_hosts|length > 0
-    changed_when: no
-
-  - name: Evaluate oo_new_etcd_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_new_etcd_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_new_etcd_hosts | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_masters_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_masters_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
-    changed_when: no
-
-  - name: Evaluate oo_etcd_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_etcd_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_etcd_hosts | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_first_etcd
-    add_host:
-      name: "{{ g_etcd_hosts[0] }}"
-      groups: oo_first_etcd
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    when: g_etcd_hosts|length > 0
-    changed_when: no
-
-  # We use two groups one for hosts we're upgrading which doesn't include embedded etcd
-  # The other for backing up which includes the embedded etcd host, there's no need to
-  # upgrade embedded etcd that just happens when the master is updated.
-  - name: Evaluate oo_etcd_hosts_to_upgrade
-    add_host:
-      name: "{{ item }}"
-      groups: oo_etcd_hosts_to_upgrade
-    with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else [] }}"
-    changed_when: False
-
-  - name: Evaluate oo_etcd_hosts_to_backup
-    add_host:
-      name: "{{ item }}"
-      groups: oo_etcd_hosts_to_backup
-    with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else (groups.oo_first_master | default([])) }}"
-    changed_when: False
-
-  - name: Evaluate oo_nodes_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_nodes_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
-    changed_when: no
-
-  - name: Evaluate oo_lb_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_lb_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_lb_hosts | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_nfs_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_nfs_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_nfs_hosts | default([]) }}"
-    changed_when: no
-
-  - name: Evaluate oo_glusterfs_to_config
-    add_host:
-      name: "{{ item }}"
-      groups: oo_glusterfs_to_config
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ g_glusterfs_hosts | union(g_glusterfs_registry_hosts | default([])) }}"
-    changed_when: no
-
-  - name: Evaluate oo_etcd_to_migrate
-    add_host:
-      name: "{{ item }}"
-      groups: oo_etcd_to_migrate
-      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
-      ansible_become: "{{ g_sudo | default(omit) }}"
-    with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config | default([]) | length != 0 else (groups.oo_first_master |default([]))}}"
-    changed_when: no

+ 0 - 11
playbooks/init/main.yml

@@ -1,11 +0,0 @@
----
-# l_install_base_packages is passed in via prerequistes.yml.
-# skip_sanity_checks is passed in via openshift-node/private/image_prep.yml
-
-- import_playbook: evaluate_groups.yml
-
-- import_playbook: basic_facts.yml
-
-# base_packages needs to be setup for openshift_facts.py to run correctly.
-- import_playbook: base_packages.yml
-  when: l_install_base_packages | default(False) | bool

+ 0 - 1
playbooks/init/roles

@@ -1 +0,0 @@
-../../roles

+ 0 - 25
playbooks/init/vars/cluster_hosts.yml

@@ -1,25 +0,0 @@
----
-g_etcd_hosts: "{{ groups.etcd | default([]) }}"
-
-g_new_etcd_hosts: "{{ groups.new_etcd | default([]) }}"
-
-g_lb_hosts: "{{ groups.lb | default([]) }}"
-
-g_master_hosts: "{{ groups.masters | default([]) }}"
-
-g_new_master_hosts: "{{ groups.new_masters | default([]) }}"
-
-g_node_hosts: "{{ groups.nodes | default([]) }}"
-
-g_new_node_hosts: "{{ groups.new_nodes | default([]) }}"
-
-g_nfs_hosts: "{{ groups.nfs | default([]) }}"
-
-g_glusterfs_hosts: "{{ groups.glusterfs | default([]) }}"
-
-g_glusterfs_registry_hosts: "{{ groups.glusterfs_registry | default(g_glusterfs_hosts) }}"
-
-g_all_hosts: "{{ g_master_hosts | union(g_node_hosts) | union(g_etcd_hosts)
-                 | union(g_new_etcd_hosts) | union(g_lb_hosts) | union(g_nfs_hosts)
-                 | union(g_new_node_hosts)| union(g_new_master_hosts)
-                 | default([]) }}"

+ 2 - 48
playbooks/openshift-node/scaleup.yml

@@ -10,53 +10,7 @@
         new_workers host group to add nodes.
     when: groups.new_workers | default([]) | length == 0
 
-- name: run the init
-  import_playbook: ../init/main.yml
-  vars:
-    l_init_fact_hosts: "new_workers"
-    l_openshift_version_set_hosts: "new_workers"
-    l_install_base_packages: True
-    l_repo_hosts: "new_workers"
-    l_base_packages_hosts: "new_workers"
-
-- name: Get release image
-  hosts: localhost
-  connection: local
-  gather_facts: no
-  tasks:
-  - name: Get release image
-    k8s_facts:
-      kubeconfig: "{{ kubeconfig_path }}"
-      kind: ClusterVersion
-      name: version
-    register: clusterversion
-    until:
-    - clusterversion.resources is defined
-    - clusterversion.resources | length > 0
-    - clusterversion.resources[0].status is defined
-    - clusterversion.resources[0].status.desired is defined
-    - clusterversion.resources[0].status.desired.image is defined
-    retries: 36
-    delay: 5
-
 - name: install nodes
   hosts: new_workers
-  tasks:
-  - import_role:
-      name: openshift_node40
-      tasks_from: install.yml
-  - name: Wait for bootstrap endpoint to show up
-    uri:
-      url: "{{ openshift_bootstrap_endpoint }}"
-      validate_certs: false
-    delay: 10
-    retries: 60
-    register: result
-    until:
-    - "'status' in result"
-    - result.status == 200
-  - import_role:
-      name: openshift_node40
-      tasks_from: config.yml
-    vars:
-      openshift_release_image: "{{ hostvars['localhost'].clusterversion.resources[0].status.desired.image }}"
+  roles:
+    - openshift_node40

+ 16 - 0
roles/openshift_node40/defaults/main.yml

@@ -1,4 +1,10 @@
 ---
+openshift_node_kubeconfig: "{{ lookup('file', kubeconfig_path) | from_yaml }}"
+openshift_node_bootstrap_port: 22623
+openshift_node_bootstrap_machineconfigpool: 'worker'
+openshift_node_bootstrap_server: "{{ openshift_node_kubeconfig.clusters.0.cluster.server.split(':')[0:-1] | join(':') }}:{{ openshift_node_bootstrap_port }}"
+openshift_node_bootstrap_endpoint: "{{ openshift_node_bootstrap_server }}/config/{{ openshift_node_bootstrap_machineconfigpool }}"
+
 openshift_release_image: "registry.svc.ci.openshift.org/openshift/origin-release:v4.0"
 ign_file: "/tmp/bootstrap.ign"
 pull_secret: "{{ files_dir }}/pull-secret"
@@ -10,6 +16,16 @@ openshift_service_type_dict:
 openshift_service_type: "{{ openshift_service_type_dict[openshift_deployment_type] }}"
 
 openshift_node_install_packages:
+  # Packages from old init/base_packages
+  - iproute
+  - dbus-python
+  - PyYAML
+  - libsemanage-python
+  - yum-utils
+  - python-docker-py
+  - systemd-journal-gateway
+  - python-ipaddress
+  # Packages from old roles/container_runtime
   - cri-o
   - cri-tools
   - podman

+ 37 - 13
roles/openshift_node40/tasks/config.yml

@@ -22,6 +22,23 @@
     state: yes
     persistent: yes
 
+- name: Wait for bootstrap endpoint to show up
+  uri:
+    url: "{{ openshift_node_bootstrap_endpoint }}"
+    validate_certs: false
+  delay: 10
+  retries: 60
+  register: result
+  until:
+  - "'status' in result"
+  - result.status == 200
+
+- name: Fetch bootstrap ignition file locally
+  uri:
+    url: "{{ openshift_node_bootstrap_endpoint }}"
+    dest: "{{ ign_file }}"
+    validate_certs: false
+
 - name: create temp directory
   tempfile:
     state: directory
@@ -32,6 +49,26 @@
     src: "{{ pull_secret }}"
     dest: "{{ tempfile.path }}/pull-secret.json"
 
+- name: Get release image
+  k8s_facts:
+    kubeconfig: "{{ kubeconfig_path }}"
+    kind: ClusterVersion
+    name: version
+  delegate_to: localhost
+  register: clusterversion
+  until:
+  - clusterversion.resources is defined
+  - clusterversion.resources | length > 0
+  - clusterversion.resources[0].status is defined
+  - clusterversion.resources[0].status.desired is defined
+  - clusterversion.resources[0].status.desired.image is defined
+  retries: 36
+  delay: 5
+
+- name: Set openshift_release_image fact
+  set_fact:
+    openshift_release_image: "{{ clusterversion.resources[0].status.desired.image }}"
+
 - name: Pull release image
   command: "podman pull --tls-verify={{ tls_verify }} --authfile {{ tempfile.path }}/pull-secret.json {{ openshift_release_image }}"
 
@@ -39,19 +76,6 @@
   command: "podman run --rm {{ openshift_release_image }} image machine-config-daemon"
   register: release_image_mcd
 
-- name: Copy bootstrap ignition file locally
-  copy:
-    src: "{{ openshift_ignition_file_path }}"
-    dest: "{{ ign_file }}"
-  when: openshift_ignition_file_path is defined
-
-- name: Fetch bootstrap ignition file locally
-  uri:
-    url: "{{ openshift_bootstrap_endpoint }}"
-    dest: "{{ ign_file }}"
-    validate_certs: false
-  when: openshift_bootstrap_endpoint is defined
-
 - block:
   - name: Pull MCD image
     command: "podman pull --tls-verify={{ tls_verify }} --authfile {{ tempfile.path }}/pull-secret.json {{ release_image_mcd.stdout }}"

+ 2 - 0
roles/openshift_node40/tasks/main.yml

@@ -0,0 +1,2 @@
+- include_tasks: install.yml
+- include_tasks: config.yml

+ 0 - 6
test/aws/scaleup.yml

@@ -1,10 +1,4 @@
 ---
-- name: run the init
-  import_playbook: ../../playbooks/init/main.yml
-  vars:
-    l_init_fact_hosts: "all:!all"
-    l_openshift_version_set_hosts: "all:!all"
-
 - name: create new nodes
   hosts: localhost
   connection: local