rancherfederal / rke2-ansible

RKE2 cluster provisioning via Ansible.
Apache License 2.0
233 stars 129 forks source link

Re-run ansible playbook after first run breaks #191

Closed pleasantencounter closed 6 months ago

pleasantencounter commented 9 months ago
- name: Add token to config.yaml
  ansible.builtin.lineinfile:
    dest: /tmp/ansible-config.txt
    line: "{{ original_token }}"
    state: present
    insertbefore: BOF
  when: previous_rke2_config.stat.exists and original_token | length > 0
  changed_when: false

 - name: Add server url to config file
  ansible.builtin.lineinfile:
    dest: /tmp/ansible-config.txt
    line: "{{ original_server }}"
    state: present
    insertbefore: BOF
  when: previous_rke2_config.stat.exists and original_server | length > 0
  changed_when: false

The following issue can be reproduced by running the playbook then updating the hosts.ini with another node and running the playbook again. The original_token and original_server vars are defined as null on the first server since it does not have the token and server address set in the /etc/rancher/rke2/config.yaml. Ansible throws an error because you can't get the length of null. Remove length in both those tasks, and by default, the when statement will result as false since those vars return null. No need to get length in that statement.

aleiner commented 6 months ago

Can't create issue on latest branch and code has been modified from your post. Please reopen if you're still have issues.