Skip to content

Commit

Permalink
Merge pull request #3 from AobaIwaki123/iwaki/lint-ansible
Browse files Browse the repository at this point in the history
Ansible Lint Workflowを追加
  • Loading branch information
AobaIwaki123 authored Dec 4, 2024
2 parents b00a8f9 + 45e4ef9 commit f4c3f43
Show file tree
Hide file tree
Showing 62 changed files with 138 additions and 92 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .github/workflows/ansible-lint.yml
name: ansible-lint
run-name: Ansible Lint
on:
pull_request:
branches:
- master
paths:
- 'roles/**'
- 'playbooks/**'
jobs:
build:
name: Ansible Lint # Naming the build is important to use it as a status check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Run ansible-lint
uses: ansible/ansible-lint@main
with:
setup_python: "true"
working_directory: ${{ github.workspace }}
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
ROLE_NAME ?= default_env
HOST_NAME ?= ""
TAG_NAME ?= ""

role:
@ansible-galaxy init roles/$(ROLE_NAME)

ping:
@ansible -i inventory/hosts all -m ping

check-diff:
@ansible-playbook -i inventory/hosts site.yml --check --diff --limit $(HOST_NAME) --tags $(TAG_NAME)

apply-role:
@ansible-playbook -i inventory/hosts site.yml --limit $(HOST_NAME) --tags $(TAG_NAME)

clean-branch:
@git remote prune origin
@git branch | xargs git branch -d
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
[![ansible-lint](https://github.com/AobaIwaki123/ansible/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/AobaIwaki123/ansible/actions/workflows/lint.yml)

# 自宅サーバーの構成管理用のAnsible

## Envirionment

- Conda: 24.9.2
- Python: 3.13.0
- Ansible: 11.0.0, https://github.com/ansible/ansible
- Ansible Core: 2.18.0

## Ansible Roleの作成
## Ansible Roleの雛形の作成

```sh
$ make role ROLE_NAME=role_name
```

## 接続先サーバーへの接続確認
## 疎通確認

```sh
$ make ping
```

## Playbookの実行
## Ansible Playbookの実行

- Check Diff After Running Playbook with Tags
### Roleの実行前に差分を確認

```sh
$ ansible-playbook -i inventory/hosts site.yml --check --diff --tags init-vm
$ make check-diff TAG_NAME={TAG_NAME} # Tagを指定して実行
$ make check-diff HOST_NAME={HOST_NAME} # Hostを指定して実行
```

- Apply Playbook with Tags
### Roleの実行

```sh
$ ansible-playbook -i inventory/hosts site.yml --tags init-vm
$ make apply-role TAG_NAME={TAG_NAME} # Tagを指定して実行
$ make apply-role HOST_NAME={HOST_NAME} # Hostを指定して実行
```

- Limit Host to apply Ansible Playbook

```sh
$ ansible-playbook -i inventory/hosts site.yml --limit {HOSTNAME}
## Show All Ansible Facts
## Ansible Factsを全て表示するタスク

```yaml
- name: Print all available facts
Expand Down
6 changes: 6 additions & 0 deletions docs/ansible-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ $ ansible-playbook -i inventory/hosts site.yml --check --diff --tags init-vm
```sh
$ ansible-playbook -i inventory/hosts site.yml --tags init-vm
```

- Limit Host to apply Ansible Playbook

```sh
$ ansible-playbook -i inventory/hosts site.yml --limit {HOSTNAME}
```
6 changes: 3 additions & 3 deletions playbooks/init-lxc/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
- name: Initialize LXC
hosts: proxmox_lxc
roles:
- {role: basic-apt-package, apt_upgrade: false}
- default-configs
- install-docker
- {role: basic_apt_package, basic_apt_package_apt_upgrade: false}
- default_configs
- install_docker
2 changes: 1 addition & 1 deletion playbooks/init-vm/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- name: Initialize VM
hosts: proxmox_vm
roles:
- basic-apt-package # 必須のパッケージをインストール
- basic_apt_package # 必須のパッケージをインストール
6 changes: 0 additions & 6 deletions roles/basic-apt-package/tests/test.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions roles/basic_apt_package/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0
---
- name: Test basic_apt_package role
hosts: localhost
remote_user: root
roles:
- basic_apt_package
File renamed without changes.
6 changes: 0 additions & 6 deletions roles/default-configs/tests/test.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions roles/default_configs/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0
---
- name: Test default_configs role
hosts: localhost
remote_user: root
roles:
- default_configs
File renamed without changes.
3 changes: 0 additions & 3 deletions roles/install-docker/defaults/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/install-docker/handlers/main.yml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/install-docker/tests/test.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/install-tailscale/defaults/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/install-tailscale/handlers/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/install-tailscale/tasks/main.yml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/install-tailscale/tests/test.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/install-tailscale/vars/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Ref

- https://medium.com/@GarisSpace/how-to-install-docker-using-ansible-01a674086f8c
- https://medium.com/@GarisSpace/how-to-install_docker-using-ansible-01a674086f8c
3 changes: 3 additions & 0 deletions roles/install_docker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# defaults file for roles/install_docker
3 changes: 3 additions & 0 deletions roles/install_docker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# handlers file for roles/install_docker
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: AobaIwaki
description: Install Docker
company: ""

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
Expand All @@ -15,9 +15,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: MIT

min_ansible_version: 2.1
min_ansible_version: '2.1'

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT-0
---
# tasks file for roles/install-docker
# tasks file for roles/install_docker
- name: Install prerequisites for Docker repository
become: true
ansible.builtin.apt:
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions roles/install_docker/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0
---
- name: Test install_docker role
hosts: localhost
remote_user: root
roles:
- install_docker
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# vars file for roles/install-docker
# vars file for roles/install_docker
File renamed without changes.
3 changes: 3 additions & 0 deletions roles/install_tailscale/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# defaults file for roles/install_tailscale
3 changes: 3 additions & 0 deletions roles/install_tailscale/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# handlers file for roles/install_tailscale
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: AobaIwaki
description: Install Tailscale
company: ""

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
Expand All @@ -15,9 +15,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: MIT

min_ansible_version: 2.1
min_ansible_version: '2.1'

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
Expand Down
3 changes: 3 additions & 0 deletions roles/install_tailscale/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# tasks file for roles/install_tailscale
File renamed without changes.
7 changes: 7 additions & 0 deletions roles/install_tailscale/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0
---
- name: Test install_tailscale role
hosts: localhost
remote_user: root
roles:
- install_tailscale
3 changes: 3 additions & 0 deletions roles/install_tailscale/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# vars file for roles/install_tailscale
3 changes: 0 additions & 3 deletions roles/setup-exporter/defaults/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/setup-exporter/handlers/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/setup-exporter/tasks/main.yml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/setup-exporter/tests/test.yml

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions roles/setup_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# defaults file for roles/setup_exporter
3 changes: 3 additions & 0 deletions roles/setup_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# handlers file for roles/setup_exporter
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: AobaIwaki
description: Setup Prometheus Node Exporter
company: ""

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
Expand All @@ -15,9 +15,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: MIT

min_ansible_version: 2.1
min_ansible_version: '2.1'

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
Expand Down
3 changes: 3 additions & 0 deletions roles/setup_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# tasks file for roles/setup_exporter
File renamed without changes.
7 changes: 7 additions & 0 deletions roles/setup_exporter/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0
---
- name: Test setup_exporter role
hosts: localhost
remote_user: root
roles:
- setup_exporter
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: MIT-0
---
# vars file for roles/setup-exporter
# vars file for roles/setup_exporter

0 comments on commit f4c3f43

Please sign in to comment.