Versions Compared

Key

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

Dear Customer, the RevolutionPi Revolution Pi is based on an open source platform, which can lead to misbehavior of the devices. To solve some problems, you can use Ansible. Because Ansible is all about automation, it requires instructions to accomplish each job. With everything written down in simple script form, it's easy to do version control and automate repetitive tasks with relative ease. Regardless of whether it is a single system or many. It is available as open source software under the GNU General Public License for DevOps around the world.

Preparation

especially for Windows users

...

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

A Playbooks.zip file is provided to solve your problem. Copy this Playbook and paste it into the Ubuntu drive (\\wls$). The "\\wls$" drive is created immediately after you install the Ubuntu app on your Windows machine. There are the following files in the playbooks.zip folder:

  • Inventory

  • ".yml" file

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

Info

Just pay attention to the folder where the playbooks is inserted. For an Ansible script to run, you must be in the folder where it is pasted. For the realization of this tutorial, the playbook.zip was copied and inserted in the root folder of the "\\wls$" drive

...

  •  Automatic copying of the public key to the target system

Ansible automates important tasks on a target system via SSH. The SSH key of the Ansible host is located on the target system. With ssh-keygen, an SSH key is generated for your target system and entered into a repository. The repository is always different.

Info

After we have created an SSH key, we can enter it manually in the authorised_keys file of the remote computer or use the ssh-copy-id command. We will use the ssh-copy-id command to simplify this process. Simply call the ssh-copy-id command and pass the path to the public key as follows:

ssh-copy-id -i <Location of the public key> Username@<host-ip-address>

Code Block
# Copying the SSH key with SSH-copy-id for the system of our example 

ssh-copy-id -i /root/.ssh/id_rsa.pub pi@192.168.0.66

  •  Cloning the repository

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

With the command ls -l, you can see all contents of the order revpi-ansible-recipes

...

  •  An "Inventory" must be created. 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
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

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

for example, 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 playbook folder contains as standard:

  • Inventory

  • "Test.yml" file

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

Type the following command in terminal of ubuntu on windows to run the "Test.yml" file

...

Enter the following declarations into the inventory

Code Block
[target]
localhost

[revpi]
<ip-adress of your host> remote_user=pi ansible_python_interpreter=/usr/bin/python3

...

For our example, we use the role network-bridge. To see all available roles

Code Block
cd roles

then

Code Block
ls -l

...

At the moment of editing this tutorial, there is only one role in the repository: network-bridge.

Now get back to the last order revpi-ansible-recipes and editing the new ansible-script (myplaybook.yml), that perform the task for the role network-bridge.

Code Block
cd ..
sudo nano myplaybook.yml

...

  •  Now run the Ansible script in terminal of ubuntu on windows
Code Block
ansible-playbook -i inventory -u pi Testmyplaybook.yml

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

...

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

Code Block
ansible bet -i inventory -m ping

...

Once the script has been successfully executed, we can see the status of the execution, as shown in the following illustration:

...