Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  •  After the installation, enter the following commands on your Ubuntu Terminal:
Code Block
sudo apt update
sudo apt install ansible tree

We have a repository on Github where all the essential elements for solving the tasks are stored. This repository can be reached through this link https://github.com/RevolutionPi/revpi-ansible-recipes.

  •  Apply the instructions below to be prepared to run an Ansible script.
Code Block
git clone https://github.com/RevolutionPi/revpi-ansible-recipes.git
cd revpi-ansible-recipes/roles

With the command ls -l, you can see the names of all the files that govern the different tasks. If you know the name of the files that governs your task, please write it down. For our example, we will use the REVPI-Switch.yml.

...

  •  The "Inventory" must be adjusted. In the inventory, you must enter the IP address of your target system. All devices on which the tasks are to be executed must be entered under [bet] as shown below

...

  • (see the picture inventory adjustment)

First, type the following command in terminal of ubuntu on windows

Code Block
unzip playbooks.zip
cd playbooks
sudo nano inventory

...

  •  SSH secures communication between your local machine and a remote system by fully encrypting that traffic. With ssh-keygen, an SSH key is created for your target system and entered into a repository. The repository is then always different. Type the following command in terminal of ubuntu on windows
Code Block
ssh-keygen
Image Removed
  •  After creating an SSH key, we can manually enter it into the authorized_keys file of the remote computer or use the ssh-copy-id command. Copy the key from the repository and save it on the target system (.ssh/authorized_keys)

Type the following command in terminal of ubuntu on windows

Code Block
cat /root/.ssh/id_rsa.pub

...

Copy the SSH-Key from cat /root/.ssh/id_rsa.pub and insert in the file .ssh/authorized_keys.

Type the following command in terminal of your Target system (The Terminal you are using to be connected to your RevPi. For example: Putty, MobaXterm)

Code Block
sudo nano .ssh/authorized_keys

...

Running the Ansible script

Example 1: To ping a device

you have received for your issue a playbooks.zip order from the Kunbus Support to apply some tasks on your device or to solve a problem.

The playbooks.zip folder contains as standard:

  • Inventory

  • "Test.yml" file

  • a folder "files" with other files in it.

Type the following command in the ubuntu terminal on Windows to ping the device you want to reach.

Code Block
cd playbooks  #if you are not if the file playbooks
ansible bet -i inventory -m ping

...

Example 2

you have received for your issue a playbooks.zip with the following content, after unzip it.

...

Test2.yml is in this case the YAML file that contains the instructions to perform a task.

Code Block
languageyaml
name: RevPi as Switch
  hosts: bet
  tasks:
    - name: Copy file src './files/interfaces' dest '/etc/network/interfaces
      become: yes
      copy:
        src: ./files/interfaces
        dest: /etc/network/interfaces
    - name: apt update cache and install bridge-utils
      become: yes
      ansible.builtin.apt:
        name: bridge-utils
        update_cache: yes
    - name: disable dhcpcd.service
      become: yes
      ansible.builtin.service:
        name: dhcpcd.service
        enabled: no
    - name: enable networking
      become: yes
      ansible.builtin.service:
        name: networking
        enabled: yes
    - name: Reboot
      become: yes
      reboot:

This script does nothing else than:

  • Copy the file "interfaces" in order files from the host to the repository "./etc/network/interfaces” in Target System

  • The following commands are then executed.

sudo systemctl disable dhcp.service
sudo systemctl enable networking
sudo reboot

...

  •  Now run the Ansible script in terminal of ubuntu on windows

...

Code Block
cd playbooks  #if you are not if the file playbooks
ansible-playbook -i inventory -u pi Test2REVPI-Switch.yml

After a successful running of the script, you will get a message like shown on the following picture:

...