Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from robertdebock/ansiblefest
Browse files Browse the repository at this point in the history
Ansiblefest
  • Loading branch information
robertdebock authored Sep 24, 2019
2 parents 06dc3b7 + 16a00cf commit 72d6dcd
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
repository:
description: Import and process RAW files.
description: Process images
homepage: https://robertdebock.nl/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ molecule/*/.molecule
*.log
*.swp
molecule/resources/out
.DS_Store
44 changes: 22 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ language: python
services: docker

env:
- version=">=2.7,<2.8" distro="alpine-latest" expectation="fail"
- version="" distro="alpine-latest" expectation="fail"
- version="devel" distro="alpine-latest" expectation="fail"
- version=">=2.7,<2.8" distro="alpine-edge" expectation="fail"
- version="" distro="alpine-edge" expectation="fail"
- version="devel" distro="alpine-edge" expectation="fail"
- version=">=2.7,<2.8" distro="alpine-latest"
- version="" distro="alpine-latest"
- version="devel" distro="alpine-latest"
- version=">=2.7,<2.8" distro="alpine-edge"
- version="" distro="alpine-edge"
- version="devel" distro="alpine-edge"
- version=">=2.7,<2.8" distro="archlinux"
- version="" distro="archlinux"
- version="devel" distro="archlinux"
- version=">=2.7,<2.8" distro="centos-6"
- version="" distro="centos-6"
- version="devel" distro="centos-6"
- version=">=2.7,<2.8" distro="centos-latest" expectation="fail"
- version="" distro="centos-latest" expectation="fail"
- version="devel" distro="centos-latest" expectation="fail"
- version=">=2.7,<2.8" distro="centos-6" expectation="fail"
- version="" distro="centos-6" expectation="fail"
- version="devel" distro="centos-6" expectation="fail"
- version=">=2.7,<2.8" distro="centos-latest"
- version="" distro="centos-latest"
- version="devel" distro="centos-latest"
- version=">=2.7,<2.8" distro="debian-stable"
- version="" distro="debian-stable"
- version="devel" distro="debian-stable"
Expand All @@ -31,9 +31,9 @@ env:
- version=">=2.7,<2.8" distro="fedora-rawhide"
- version="" distro="fedora-rawhide"
- version="devel" distro="fedora-rawhide"
- version=">=2.7,<2.8" distro="opensuse-leap" expectation="fail"
- version="" distro="opensuse-leap" expectation="fail"
- version="devel" distro="opensuse-leap" expectation="fail"
- version=">=2.7,<2.8" distro="opensuse-leap"
- version="" distro="opensuse-leap"
- version="devel" distro="opensuse-leap"
- version=">=2.7,<2.8" distro="ubuntu-rolling"
- version="" distro="ubuntu-rolling"
- version="devel" distro="ubuntu-rolling"
Expand All @@ -46,13 +46,13 @@ env:

matrix:
allow_failures:
- env: version=">=2.7,<2.8" distro="alpine-edge" expectation="fail"
- env: version="" distro="alpine-edge" expectation="fail"
- env: version="devel" distro="alpine-edge" expectation="fail"
- env: version="devel" distro="alpine-latest" expectation="fail"
- env: version=">=2.7,<2.8" distro="alpine-edge"
- env: version="" distro="alpine-edge"
- env: version="devel" distro="alpine-edge"
- env: version="devel" distro="alpine-latest"
- env: version="devel" distro="archlinux"
- env: version="devel" distro="centos-6"
- env: version="devel" distro="centos-latest" expectation="fail"
- env: version="devel" distro="centos-6" expectation="fail"
- env: version="devel" distro="centos-latest"
- env: version="devel" distro="debian-stable"
- env: version=">=2.7,<2.8" distro="debian-unstable"
- env: version="" distro="debian-unstable"
Expand All @@ -61,7 +61,7 @@ matrix:
- env: version=">=2.7,<2.8" distro="fedora-rawhide"
- env: version="" distro="fedora-rawhide"
- env: version="devel" distro="fedora-rawhide"
- env: version="devel" distro="opensuse-leap" expectation="fail"
- env: version="devel" distro="opensuse-leap"
- env: version="devel" distro="ubuntu-rolling"
- env: version=">=2.7,<2.8" distro="ubuntu-devel"
- env: version="" distro="ubuntu-devel"
Expand Down
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ y
<img src="https://docs.ansible.com/ansible-tower/3.2.4/html_ja/installandreference/_static/images/logo_invert.png" width="10%" height="10%" alt="Ansible logo" align="right"/>
<a href="https://travis-ci.org/robertdebock/ansible-role-y"><img src="https://travis-ci.org/robertdebock/ansible-role-y.svg?branch=master" alt="Build status" align="left"/></a>

Import and process RAW files.
Process images

Example Playbook
----------------
Expand All @@ -17,13 +17,12 @@ This example is taken from `molecule/resources/playbook.yml`:
become: yes
gather_facts: yes

vars:
y_import_from: /data/in
y_export_to: out
y_preset: monochrome

roles:
- robertdebock.y
- role: robertdebock.y
y_import_from: /data/in
y_export_to: out
y_presets:
- name: monochrome
```
The machine you are running this on, may need to be prepared.
Expand All @@ -39,7 +38,7 @@ The machine you are running this on, may need to be prepared.
- robertdebock.epel

tasks:
- name: create /data
- name: create directories in container
file:
path: "{{ item }}"
state: directory
Expand All @@ -48,12 +47,10 @@ The machine you are running this on, may need to be prepared.
- /data/in
- /data/out

- name: copy samples files to /data
- name: copy samples files to /data/in
copy:
src: "{{ item }}"
src: in/
dest: /data/in
with_items:
- sample.RAF
```
Also see a [full explanation and example](https://robertdebock.nl/how-to-use-these-roles.html) on how to use these roles.
Expand All @@ -66,13 +63,16 @@ These variables are set in `defaults/main.yml`:
---
# defaults file for y
y_import_from: /tmp/import
y_export_to: /tmp/export
# y_presets is a list of presets that will be applied to images.
# y_presets:
# - name: monochrome
y_convert_images: yes
# y_import_from defines the path where to pickup files from.
# This could be /dev/sdb1 (for some SD-card) for example.
y_import_from: /tmp/import
y_preset:
- name: monochrome
# y_export_to is the path where the images will be saved.
y_export_to: /tmp/export
```

Requirements
Expand Down Expand Up @@ -106,22 +106,33 @@ This role has been tested against the following distributions and Ansible versio

|distribution|ansible 2.7|ansible 2.8|ansible devel|
|------------|-----------|-----------|-------------|
|alpine-edge*|no|no|no*|
|alpine-latest|no|no|no*|
|alpine-edge*|yes|yes|yes*|
|alpine-latest|yes|yes|yes*|
|archlinux|yes|yes|yes*|
|centos-6|yes|yes|yes*|
|centos-latest|no|no|no*|
|centos-6|no|no|no*|
|centos-latest|yes|yes|yes*|
|debian-stable|yes|yes|yes*|
|debian-unstable*|yes|yes|yes*|
|fedora-latest|yes|yes|yes*|
|fedora-rawhide*|yes|yes|yes*|
|opensuse-leap|no|no|no*|
|opensuse-leap|yes|yes|yes*|
|ubuntu-devel*|yes|yes|yes*|
|ubuntu-latest|yes|yes|yes*|
|ubuntu-rolling|yes|yes|yes*|

A single star means the build may fail, it's marked as an experimental build.

Exceptions
----------

Some variarations of the build matrix do not work. These are the variations and reasons why the build won't work:

| variation | reason |
|---------------------------|------------------------|
| CentOS 6 | Somehow ImageMagick creates a different file each run. Not idempotent. |



Testing
-------

Expand Down
13 changes: 8 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
# defaults file for y

y_import_from: /tmp/import
y_export_to: /tmp/export
# y_presets is a list of presets that will be applied to images.
# y_presets:
# - name: monochrome

y_convert_images: yes
# y_import_from defines the path where to pickup files from.
# This could be /dev/sdb1 (for some SD-card) for example.
y_import_from: /tmp/import

y_preset:
- name: monochrome
# y_export_to is the path where the images will be saved.
y_export_to: /tmp/export
4 changes: 4 additions & 0 deletions meta/exception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
exceptions:
- variation: CentOS 6
reason: Somehow ImageMagick creates a different file each run. Not idempotent.
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
galaxy_info:
author: Robert de Bock
role_name: y
description: Import and process RAW files.
description: Process images
license: Apache-2.0
company: none
min_ansible_version: 2.6
Expand Down
2 changes: 2 additions & 0 deletions molecule/centos-latest/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ provisioner:
converge: ../resources/playbook.yml
scenario:
name: centos-latest
converge_sequence:
- converge
Binary file added molecule/resources/in/sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions molecule/resources/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
become: yes
gather_facts: yes

vars:
y_import_from: /data/in
y_export_to: out
y_preset: monochrome

roles:
- ansible-role-y
- role: ansible-role-y
y_import_from: /data/in
y_export_to: out
y_presets:
- name: monochrome
8 changes: 3 additions & 5 deletions molecule/resources/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- robertdebock.epel

tasks:
- name: create /data
- name: create directories in container
file:
path: "{{ item }}"
state: directory
Expand All @@ -18,9 +18,7 @@
- /data/in
- /data/out

- name: copy samples files to /data
- name: copy samples files to /data/in
copy:
src: "{{ item }}"
src: in/
dest: /data/in
with_items:
- sample.RAF
Binary file removed molecule/resources/sample.RAF
Binary file not shown.
57 changes: 3 additions & 54 deletions tasks/image.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,4 @@
---
- name: save the year
shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%Y" | grep "Create Date" | awk '{print $NF}'
args:
creates: nothing
executable: /bin/bash
register: year
changed_when: no
check_mode: no

- name: save the month
shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%m" | grep "Create Date" | awk '{print $NF}'
args:
creates: nothing
executable: /bin/bash
register: month
changed_when: no
check_mode: no

- name: save the day
shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%d" | grep "Create Date" | awk '{print $NF}'
args:
creates: nothing
executable: /bin/bash
register: day
changed_when: no
check_mode: no

- name: ensure directory structure exists
file:
path: "{{ y_export_path }}"
state: directory

- name: process images
block:
- name: processing {{ image.path | basename }}
shell: dcraw -c "{{ y_command_options[y_preset] }}" "{{ image.path }}" > "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm"
args:
creates: "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm"

- name: copying processed image back
fetch:
src: "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm"
dest: "{{ y_export_to }}/{{ (image.path | basename | splitext)[0] }}.pgm"
flat: yes
when:
- y_convert_images | bool

- name: copying unprocessed image back
fetch:
src: "{{ y_export_path }}/{{ (image.path | basename }}"
dest: "{{ y_export_to }}"
flat: yes
when:
- not y_convert_images | bool
- name: apply presets
include: "{{ item.name }}.yml"
loop: "{{ y_presets }}"
26 changes: 20 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,34 @@
until: y_install_requirements is succeeded
retries: 3

- name: create export directory
file:
path: "{{ y_export_to }}"
state: directory

- name: find files to convert {{ y_import_from }}
find:
path: "{{ y_import_from }}"
excludes: "*.pgm"
patterns: "*.jpg"
when:
- y_import_from is defined
register: y_files
register: y_find

- name: loop over found images
include: image.yml
with_items: "{{ y_files.files }}"
loop: "{{ y_find.files }}"
loop_control:
loop_var: image
when:
- y_files is defined
- y_files.files is defined
- y_files.files
- y_find is defined
- y_find.files is defined
- y_find.files

- name: copy converted images back
fetch:
src: "{{ item.path }}"
dest: "{{ y_export_to }}/{{ item.path | basename }}"
flat: yes
loop: "{{ y_find.files }}"
loop_control:
label: "{{ item.path }}"
4 changes: 4 additions & 0 deletions tasks/monochrome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: convert to monochrome
command: convert {{ image.path }} -monochrome {{ image.path }}
changed_when: no
Loading

0 comments on commit 72d6dcd

Please sign in to comment.