generated from 39services/ansible_collection_39systems.template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,3 +149,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
*.mp4 | ||
*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,32 @@ | ||
Ansible Collection - diademiemi.template | ||
Ansible Collection - diademiemi.bad_apple | ||
======================================== | ||
Documentation for the collection template. | ||
|
||
Contents | ||
======== | ||
|
||
Roles | ||
------ | ||
Role | Description | CI Status | ||
--- | --- | --- | ||
<!-- [diademiemi.template.EXAMPLE](./roles/template/) | Install EXAMPLE | [![Molecule test](https://github.com/diademiemi/ansible_collection_diademiemi.template/actions/workflows/ansible-role-EXAMPLE.yml/badge.svg)](https://github.com/diademiemi/ansible_collection_diademiemi.template/actions/workflows/ansible-role-EXAMPLE.yml) --> | ||
|
||
Click on the role to see the README for that role. | ||
|
||
Collection Structure | ||
-------------- | ||
|
||
This collection makes use of my [Ansible Role Template repository](https://github.com/diademiemi/ansible_role_%74emplate.git). The `add-role.sh` script downloads this Template and generates a new role with the name specified. If a `molecule/default/molecule.yml` file is present, it will be ran with GitHub Actions. | ||
<!-- I use %74 here to encode to a "t" so it doesnt get recursively replaced. The .git causes a redirect so you end up at the right URL :)--> | ||
|
||
Usage: | ||
Documentation for the collection bad_apple. | ||
|
||
This is an Ansible Collection which features: | ||
- A module `render_frame` which converts a frame of the Bad Apple video into an ASCII art representation. | ||
- A playbook `bad-apple.yml` which: | ||
- Installs necessary Pip packages. | ||
- Downloads the Bad Apple video. | ||
- Splits the video into PNG frames. | ||
- Renders each frame into an ASCII art representation. | ||
- Displays the ASCII art representation of each frame in the terminal. | ||
|
||
To run the playbook, install the collection and run the playbook: | ||
```bash | ||
export NEW_ROLE_NAME="new_role" | ||
./add-role.sh ${NEW_ROLE_NAME} | ||
ansible-galaxy collection install diademiemi.bad_apple | ||
``` | ||
|
||
Using Template | ||
-------------- | ||
To use this template for a new role, run | ||
|
||
|
||
OR locally | ||
```bash | ||
export NEW_ROLE_NAME="NEW_NAME" | ||
export GITHUB_USER="diademiemi" | ||
export GALAXY_API_KEY="YOUR_API_KEY" | ||
|
||
find . -type f -exec sed -i "s/diademiemi/${GITHUB_USER}/g" {} + # Do not run this more than once | ||
find . -type f -exec sed -i "s/template/${NEW_ROLE_NAME}/g" {} + # Do not run this more than once | ||
|
||
# Assumes repo is named ansible_role_${NEW_ROLE_NAME} | ||
gh secret set GALAXY_API_KEY -R ${GITHUB_USER}/ansible_collection_${GITHUB_USER}.${NEW_COLLECTION_NAME} -a actions -b ${GALAXY_API_KEY} | ||
ansible-galaxy collection install . | ||
``` | ||
|
||
# Remove this section from README.md | ||
sed -i "/Using Template/Q" README.md | ||
Then run the playbook: | ||
```bash | ||
ansible-playbook playbooks/bad-apple.yml -K | ||
``` | ||
OR to skip installing Pip packages (`yt-dlp` and `Pillow`) | ||
```bash | ||
ansible-playbook playbooks/bad-apple.yml --skip-tags prereq | ||
``` | ||
|
||
This is also provided as a script as `replace.sh`. | ||
Wait 20 minutes and enjoy Bad Apple in Ansible! |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
major_changes: | ||
- add render_frame module | ||
- add bad-apple playbook | ||
|
||
release_summary: Create Bad Apple playbook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
- name: Bad Apple | ||
hosts: localhost | ||
tasks: | ||
- name: Install python packages | ||
tags: prereq | ||
ansible.builtin.include_role: | ||
name: diademiemi.python.pip | ||
vars: | ||
python_pip_user_packages: | ||
- user: "{{ ansible_user_id }}" | ||
packages: | ||
- name: yt-dlp | ||
- name: Pillow | ||
|
||
- name: Download Video | ||
tags: download | ||
ansible.builtin.command: yt-dlp -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio https://www.youtube.com/watch?v=FtutLA63Cp8 -o bad_apple.mp4 | ||
args: | ||
creates: bad_apple.mp4 | ||
|
||
- name: Ensure frame directory exists | ||
tags: frames | ||
ansible.builtin.file: | ||
path: frames | ||
state: directory | ||
mode: '0755' | ||
|
||
- name: Extract Frames | ||
tags: frames | ||
ansible.builtin.command: ffmpeg -i bad_apple.mp4 -vf fps=20 frames/bad_apple_%02d.png | ||
args: | ||
creates: frames/bad_apple_01.png | ||
|
||
- name: Get all frames | ||
tags: frames | ||
ansible.builtin.find: | ||
paths: frames | ||
patterns: '*.png' | ||
register: frames | ||
|
||
- name: Render Frame | ||
tags: render | ||
diademiemi.bad_apple.render_frame: | ||
input_file: "{{ item }}" | ||
register: result | ||
loop: "{{ frames.files | map(attribute='path') | list }}" | ||
|
||
- name: Debug | ||
tags: render | ||
ansible.builtin.debug: | ||
msg: "{{ result.results }}" | ||
|
||
- name: Show frame | ||
tags: render | ||
ansible.builtin.debug: | ||
msg: "{{ item }}" | ||
loop: "{{ result.results | map(attribute='frame') | list }}" | ||
loop_control: | ||
pause: 0.0466 | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from ansible.module_utils.basic import AnsibleModule | ||
from PIL import Image | ||
|
||
def image_to_text_grid(input_image_path, grid_width=100, grid_height=30): | ||
# Load the image | ||
image = Image.open(input_image_path) | ||
|
||
# Resize the image to match the grid size | ||
image = image.resize((grid_width, grid_height)) | ||
|
||
# Convert the image to grayscale | ||
image = image.convert('L') | ||
|
||
# Define ASCII characters for different brightness levels | ||
ascii_chars = " .:-=+*#%@" | ||
|
||
# Calculate the range of each brightness level | ||
step = 256 // len(ascii_chars) | ||
|
||
# Create the text grid | ||
text_grid = [] | ||
for y in range(grid_height): | ||
line = "" | ||
for x in range(grid_width): | ||
brightness = image.getpixel((x, y)) | ||
char_index = min(brightness // step, len(ascii_chars) - 1) | ||
line += ascii_chars[char_index] | ||
text_grid.append(line) | ||
|
||
print(text_grid) | ||
|
||
return text_grid | ||
|
||
def run_module(): | ||
module_args = dict( | ||
input_file=dict(type='str', required=True), | ||
) | ||
|
||
result = dict( | ||
changed=False, | ||
message='' | ||
) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
|
||
input_file = module.params['input_file'] | ||
|
||
frame = image_to_text_grid(input_file) | ||
|
||
result['msg'] = "Frame rendered to module output" | ||
result['frame'] = frame | ||
result['changed'] = True | ||
|
||
module.exit_json(**result) | ||
|
||
def main(): | ||
run_module() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file was deleted.
Oops, something went wrong.