This is an old revision of the document!
Table of Contents
Ansible Playbook - Update
In the previous step we discovered and added the IP address of all our nodes to the file on NUC 2: /home/ansible/my-project/hosts
Our first Ansible playbook will be to update Ubuntu packages on all the worker nodes.
Purpose:
- Demonstrate a very useful playbook
- Update all our nodes to the latest code
Step 1 - Connect to the Ansible Control Node
Step 2 - Create the Playbook
Create file /home/ansible/my-project/update.yml
- update.yml
--- - hosts: nodes become: true become_user: root tasks: - name: Update apt repo and cache on all Debian/Ubuntu boxes apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 - name: Upgrade all packages on servers apt: upgrade=dist force_apt_get=yes - name: Check if a reboot is needed on all servers register: reboot_required_file stat: path=/var/run/reboot-required get_md5=no - name: Reboot the box if kernel updated reboot: msg: "Reboot initiated by Ansible for kernel updates" connect_timeout: 5 reboot_timeout: 300 pre_reboot_delay: 0 post_reboot_delay: 30 test_command: uptime when: reboot_required_file.stat.exists
Step 3 - Test the Playbook
ansible-playbook -i hosts update.yml
DNS Name Resolution Issues
It's not great, but some servers are inconsistent in resolving DNS names using DHCP.
Here is a quick fix I have used in the past:
ansible -i hosts all -a dhclient
This can get you name resolution, but you many have two IP addresses!
Current things to test better solutions:
sudo netplan apply
sudo reboot
Next Step
Congratulations you just updated your nodes! Next is your second Ansible playbook - Ansible Playbook - CMOS.
Optional
Faster Bootup Times with WiFi Only
Set the ethernet interface to be “optional” on the nodes so they will boot faster; they normally wait for the network to come up on the wired interface. Since we are on WiFi only, the interface will never come up.
Steps:
- Create file /home/ansible/my-project/ethernetoptional.yml
- ethnetoptional.yml
--- - hosts: nodes become: true become_user: root tasks: - name: Set ethernet interface to optional lineinfile: path: /etc/netplan/00-installer-config.yaml insertafter: "dhcp4: true" line: " optional: true" - name: Apply netplan command: netplan apply ignore_errors: true
- Test the playbook
ansible-playbook -i hosts ethernetoptional.yml
Check the WiFi on the NUC
Sometimes in my Lab testing I find a NUCs that seem slowing or become unresponsive. This can actually be due to a poor WiFi connection!
- Create the playbook check-wifi.yml
- check-wifi.yml
--- - name: Check wifi strength hosts: clients remote_user: ansible become: true tasks: - name: Make sure wireless-tools is installed apt: name: wireless-tools state: present - name: Gather wifi strength shell: "iwconfig | grep Quality" register: wifi changed_when: false - name: Display wifi strength debug: msg: "{{ item }}" with_items: "{{ wifi.stdout_lines }}" - name: Calculate wifi strength set_fact: strength: "{{ wifi.stdout | regex_search(regexp, '\\1') }}" vars: regexp: 'Quality=([0-9]+)/70' - name: Show value debug: msg: - "{{ strength[0] }}/70 = {{( ( (strength[0] | int) / 70) * 100 ) | int }}%"
- Run it:
ansible-playbook -i hosts check-wifi.yml
- If all the NUCs are in the same place but one is much weaker than the others
- check the antennas are connected to the Wifi card
- does a different wifi card improve the connection?