Skip to content

Commit

Permalink
Merge pull request #103 from lafeychine/ci-improvement
Browse files Browse the repository at this point in the history
Add `ansible-lint`
  • Loading branch information
jocelynj authored Nov 7, 2023
2 parents 09e0a19 + f25a283 commit 1e0340c
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 30 deletions.
490 changes: 490 additions & 0 deletions .config/ansible-lint-ignore.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions .config/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
profile: production

enable_list:
- empty-string-compare
- no-log-password
- no-prompting
- no-same-owner

offline: true
...
27 changes: 13 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
name: CI

on: [push, pull_request]
on: [fork, pull_request, push]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends \
pylama \
python3-pylama \
yamllint
- name: Setup Python
uses: actions/setup-python@v4
with:
cache: 'pip'

- uses: actions/checkout@v3
- name: Install Python dependencies
run: pip install -U -r requirements.txt

- name: yamllint
run: |
yamllint .
- name: Run ansible-lint
run: ansible-lint

- name: pylama
run: |
pylama
- name: Run Pylama
run: pylama
2 changes: 0 additions & 2 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ rules:
document-start: disable
truthy:
allowed-values: ['true', 'false', 'True', 'False', 'yes', 'no']
ignore: |
.github/workflows/ci.yml
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,49 @@ This repository contains various scripts to setup and configure machines
handled by OSM-FR association (a french association for OpenStreetMap). These
scripts are used with [ansible](https://www.ansible.com/).

## Configuring ansible
## Installing dependencies

### Installing on Debian

A version of ansible >= 2.3 is sufficient, and is available in Debian,
or from [git repository](https://github.com/ansible/ansible.git). To install all
dependency on Debian, use:

```shell
apt-get install ansible python-jmespath
apt-get install ansible
```

To install VM through proxmox, python promoxer module is necessary, It can be
installed with:

```shell
sudo pip install proxmoxer
apt-get install python3-proxmoxer
```

### Installing using `venv`

`venv` module creates isolated Python environments.

First of all, install the required packages. On Debian, use:

```shell
apt-get install python3 python3-venv
```

You can jump into a new isolated environments using:

```shell
python3 -m venv <folder> # Create the environment, only needs to be done once
source <folder>/bin/activate # Run a subshell using the environment
```

Then, install the required packages:

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

Note: The created environment folder should be placed outside this project folder to prevent `ansible-lint` from looking at it.

## Using ansible scripts

Expand Down
2 changes: 1 addition & 1 deletion accounts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: default configuration
- name: Default configuration
hosts: all
gather_facts: no
become: yes
Expand Down
2 changes: 1 addition & 1 deletion pylama.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pylama]
skip = galaxy/*
ignore = E111,E221,E501,C901
ignore = E111,E121,E221,E501,C901
max_line_length = 160
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ansible ~= 8.0
ansible-lint ~= 6.0
proxmoxer ~= 1.0
pylama ~= 8.0
16 changes: 9 additions & 7 deletions roles/accounts/tasks/account.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
---
- name: Set {{ user }} group
group:
- name: Set group {{ user }}
ansible.builtin.group:
name: "{{ user }}"

- name: Set {{ user }} account
user:
- name: Set account {{ user }}
ansible.builtin.user:
group: "{{ user }}"
home: "{{ workspace }}/{{ user }}"
name: "{{ user }}"
uid: "{{ uid }}"

- name: Initialise folders for {{ user }}
file:
ansible.builtin.file:
path: "{{ file }}"
state: directory
group: "{{ user }}"
owner: "{{ user }}"
mode: u=rwx,g=rx,o=rx
loop:
- "/data/work/{{ user }}"
- "{{ workspace }}/{{ user }}"
loop_control:
loop_var: file

- name: Copy SSH key of user {{ user }}
authorized_key:
ansible.posix.authorized_key:
user: "{{ user }}"
key: "{{ lookup('file', file) }}"
with_fileglob:
Expand All @@ -32,12 +33,13 @@
loop_var: file

- name: Copy default config files
copy:
ansible.builtin.copy:
force: false
src: "default{{ file }}"
dest: "{{ workspace }}/{{ user }}/{{ file }}"
group: "{{ user }}"
owner: "{{ user }}"
mode: u=rw,g=r,o=r
loop:
- .gitconfig
- .vimrc
Expand Down
4 changes: 2 additions & 2 deletions roles/accounts/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Set accounts
include_tasks: account.yml
ansible.builtin.include_tasks: account.yml
vars:
service: "{{ item.value.service | default(false) }}"
uid: "{{ item.value.uid | default(omit) }}"
user: "{{ item.user }}"
workspace: "{{ '/data/project' if item.value.service | default(false) else '/home' }}"
loop: "{{ accounts__users | dict2items(key_name = 'user') }}"
loop: "{{ accounts__users | dict2items(key_name='user') }}"
when: "item.user in group_names or (item.value.admin | default(false))"
...

0 comments on commit 1e0340c

Please sign in to comment.