Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poc greengrass airbus #58

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions deployment/edge/ansible/README.md

This file was deleted.

1 change: 1 addition & 0 deletions deployment/edge/aws/ansible/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
File renamed without changes.
34 changes: 34 additions & 0 deletions deployment/edge/aws/ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Ansible repo to setup remote devices

## Setup the remote devices passwordless using SSH

- Set the different host devices inside the [inventory.ini](inventory.ini) providing user and password.
- Generate a public and private SSH key if you don't already have one using `ssh-keygen -t rsa -b 4096 -C "comment|email"` command.
- Define the `SSH_PUB_KEY_PATH` environment variable as the path to your SSH public key
- Run the following playbook:
```shell
ansible-playbook -i inventory.ini playbook/setup_ssh_key.yml
```

## Define local vio directory

Before launching ansible export a env to specify your local vio directory
```
export LOCAL_VIO_DIR=
```


### Install sshpass
https://stackoverflow.com/questions/42835626/ansible-to-use-the-ssh-connection-type-with-passwords-you-must-install-the-s

```
pip install -r requirements.txt
```

## docker-compose devices

We are adding those devices to be able to trigger capture from 2 cameras connected on the usb port of your edge.

devices:
- /dev/video0:/dev/video0
- /dev/video2:/dev/video2
18 changes: 18 additions & 0 deletions deployment/edge/aws/ansible/inventories/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

aws_access_key_id: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
aws_secret_access_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
aws_session_token: "{{ lookup('env', 'AWS_SESSION_TOKEN') }}"

aws_iot_greengrass_core_software: greengrass-nucleus-latest.zip
aws_iot_greengrass_group: ggc_group
aws_iot_greengrass_user: ggc_user
aws_iot_greengrass_password: "{{ lookup('env', 'AWS_IOT_GREENGRASS_PASSWORD') }}"
greengrass_aws_region: eu-west-1
greengrass_root_dir: /greengrass/v2/

greengrass_thing_name: bapo-raspberry
greengrass_thing_group_name: bapo-group
greengrass_thing_policy_name: bapo-greengrass-policy
greengrass_iam_tmp_role_name: bapo-iam-role-for-greengrass
greengrass_iam_tmp_role_alias_name: bapo-iam-role-alias-for-greengrass
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[edge_0]
192.168.1.87 ansible_user=pi

[edge_1]
10.103.252.192 ansible_user=devkit ansible_password=devkit

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: "Set up the device environment for AWS IoT Greengrass Core software"
hosts: all
roles:
- role: roles/check_env_vars
vars:
env_vars: [SSH_PUB_KEY_PATH, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_IOT_GREENGRASS_PASSWORD]
- role: roles/setup_device_in_passwordless_mode_with_ssh
- role: roles/install_required_tools
- role: roles/create_user_for_aws_iot_greengrass
become: true
- role: staticdev.pyenv
vars:
pyenv_env: 'user'
pyenv_global: ["3.9"]
pyenv_python_versions: ["3.9"]
pyenv_enable_autocompletion: true
pyenv_owner: "{{ aws_iot_greengrass_user }}"
pyenv_owner_group: "{{ aws_iot_greengrass_group }}"
pyenv_path: "/home/{{ aws_iot_greengrass_user }}/.pyenv"
- role: roles/download_aws_iot_greengrass_core_software
remote_user: root
- role: roles/install_aws_iot_greengrass_core_software
- role: roles/install_docker
become: true
5 changes: 5 additions & 0 deletions deployment/edge/aws/ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# requirements.yml
---

roles:
- name: staticdev.pyenv
11 changes: 11 additions & 0 deletions deployment/edge/aws/ansible/roles/check_env_vars/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: Check credentials are set as environment variables
assert:
that:
- "{{ lookup('env', item) is defined }}"
- "{{ lookup('env', item) | length > 0 }}"
- "{{ lookup('env', item) != None }}"
fail_msg: "{{ item }} environment variable needs to be set for the role to work"
success_msg: "Required variable {{ item }} is defined"
loop: "{{ env_vars }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

- name: Ensure group "{{ aws_iot_greengrass_group }}" exists
ansible.builtin.group:
name: "{{ aws_iot_greengrass_group }}"
state: present

- name: Add the user "{{ aws_iot_greengrass_user }}" with a primary group of "{{ aws_iot_greengrass_group }}"
ansible.builtin.user:
name: "{{ aws_iot_greengrass_user }}"
group: "{{ aws_iot_greengrass_group }}"
password: "{{ aws_iot_greengrass_password }}"
create_home: yes
expires: -1
update_password: always

- name: Change "{{ aws_iot_greengrass_user }}" password
ansible.builtin.shell: "chage --list {{ aws_iot_greengrass_user }}"

- name: Add the user "{{ aws_iot_greengrass_user }}" to docker group
ansible.builtin.user:
name: "{{ aws_iot_greengrass_user }}"
group: docker

- name: Set authorized key taken from file
ansible.posix.authorized_key:
user: "{{ aws_iot_greengrass_user }}"
state: present
key: "{{ lookup('file', lookup('env','SSH_PUB_KEY_PATH')) }}"

- name: Allow the "root" user to run any commands
community.general.sudoers:
name: allow-all-to-root
state: present
user: root
commands: ALL

- name: Print /etc/sudoers file to check root permissions
ansible.builtin.shell: cat /etc/sudoers
become: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

- name: Download the latest version of the AWS IoT Greengrass Core software
ansible.builtin.get_url:
url: https://d2s8p88vqu9w66.cloudfront.net/releases/{{ aws_iot_greengrass_core_software }}
dest: /tmp/{{ aws_iot_greengrass_core_software }}

- name: Verify the Greengrass nucleus software signature
ansible.builtin.shell: jarsigner -verify -certs -verbose /tmp/{{ aws_iot_greengrass_core_software }}
register: resultVerification
failed_when: (resultVerification.stdout) == "jar is unsigned."

- name: Create "/home/{{ aws_iot_greengrass_user }}/GreengrassInstaller" directory if it does not exist
ansible.builtin.file:
path: "/home/{{ aws_iot_greengrass_user }}/GreengrassInstaller"
state: directory
mode: '0755'
recurse: yes
owner: "{{ aws_iot_greengrass_user }}"
group: "{{ aws_iot_greengrass_group }}"
become: true

- name: Unzip the AWS IoT Greengrass Core software to a folder
ansible.builtin.unarchive:
src: /tmp/{{ aws_iot_greengrass_core_software }}
dest: /home/{{ aws_iot_greengrass_user }}/GreengrassInstaller
remote_src: yes
become: true

- name: See the version of the AWS IoT Greengrass Core software
ansible.builtin.shell: java -jar /home/{{ aws_iot_greengrass_user }}/GreengrassInstaller/lib/Greengrass.jar --version
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

- name: "Get stats of on {{ greengrass_root_dir }} directory"
ansible.builtin.stat:
path: "{{ greengrass_root_dir }}"
register: gg_dir

- name: "Get stats of on /etc/systemd/system/greengrass.service"
ansible.builtin.stat:
path: /etc/systemd/system/greengrass.service
register: gg_service_file

- name: Install the AWS IoT Greengrass Core software
ansible.builtin.shell: |
java -Droot="{{ greengrass_root_dir }}" -Dlog.store=FILE \
-jar ./GreengrassInstaller/lib/Greengrass.jar \
--aws-region {{ greengrass_aws_region }} \
--thing-name {{ greengrass_thing_name }} \
--thing-group-name {{ greengrass_thing_group_name }} \
--thing-policy-name {{ greengrass_thing_policy_name }} \
--tes-role-name {{ greengrass_iam_tmp_role_name }} \
--tes-role-alias-name {{ greengrass_iam_tmp_role_alias_name }} \
--component-default-user {{ aws_iot_greengrass_user }}:{{ aws_iot_greengrass_group }} \
--provision true \
--setup-system-service true \
--deploy-dev-tools true
args:
chdir: /home/{{ aws_iot_greengrass_user }}
become_user: root
become: true
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key_id }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_access_key }}"
AWS_SESSION_TOKEN: "{{ aws_session_token }}"
when: not gg_dir.stat.exists and not gg_service_file.stat.exists

- name: Enable service greengrass and ensure it is not masked
ansible.builtin.systemd_service:
name: greengrass
enabled: true
state: started
masked: no
38 changes: 38 additions & 0 deletions deployment/edge/aws/ansible/roles/install_docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for install_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker compose "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for install_docker
34 changes: 34 additions & 0 deletions deployment/edge/aws/ansible/roles/install_docker/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
48 changes: 48 additions & 0 deletions deployment/edge/aws/ansible/roles/install_docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# tasks file for install_docker

- name: Create /etc/apt/keyrings
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: '0755'

- name: Add Docker GPG apt Key
ansible.builtin.get_url:
url: https://download.docker.com/linux/raspbian/gpg
dest: /etc/apt/keyrings/docker.asc

- name: Add Docker Repository
apt_repository:
repo: "deb [arch=armhf signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/raspbian buster stable"
state: present

- name: Update apt and install docker and useful plugins
apt:
name: "{{ item }}"
state: latest
update_cache: true
loop: [docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin, docker-compose-plugin]

- name: Copy docker-compose file with owner and permissions
ansible.builtin.copy:
src: files/docker-compose
dest: /usr/bin/docker-compose
owner: root
group: root
mode: '0755'

- name: Enable service docker and ensure it is not masked
ansible.builtin.systemd_service:
name: "{{ item }}"
enabled: true
state: restarted
masked: no
loop: ["docker", "containerd"]

- name: Add user to docker group
user:
name: "{{ item }}"
groups: docker
append: yes
loop: ["pi", "{{ aws_iot_greengrass_user }}"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- install_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for install_docker
Loading