Skip to content

Commit e7fc3af

Browse files
authored
Merge pull request #31 from Oefenweb/cs-fixes
Make use of fully-qualified collection name
2 parents 82ab756 + 4b15ae5 commit e7fc3af

18 files changed

+73
-57
lines changed

.github/workflows/ci.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ jobs:
2323
python-version: '3.x'
2424

2525
- name: Install test dependencies
26-
run: pip install ansible-lint[community,yamllint]
26+
run: |
27+
pip install ansible-lint
28+
ansible-galaxy install -r requirements.yml
2729
2830
- name: Lint code
2931
run: |
@@ -43,11 +45,8 @@ jobs:
4345
matrix:
4446
include:
4547
- distro: debian8
46-
ansible-version: '<2.10'
4748
- distro: debian9
4849
- distro: debian10
49-
- distro: ubuntu1604
50-
ansible-version: '>=2.9, <2.10'
5150
- distro: ubuntu1604
5251
ansible-version: '>=2.10, <2.11'
5352
- distro: ubuntu1604

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ ansible.cfg
2828
# Other files #
2929
###############
3030
!empty
31+
32+
files/id_rsa*

Dockerfile

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
FROM ubuntu:16.04
1+
FROM ubuntu:18.04
22
MAINTAINER Mischa ter Smitten <[email protected]>
33

4+
ENV LANG C.UTF-8
5+
ENV LC_ALL C.UTF-8
6+
47
# python
58
RUN apt-get update && \
6-
DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal python-dev curl && \
9+
DEBIAN_FRONTEND=noninteractive apt-get install -y python3-minimal python3-dev curl && \
710
apt-get clean
8-
RUN curl -sL https://bootstrap.pypa.io/pip/2.7/get-pip.py | python -
11+
RUN curl -sL https://bootstrap.pypa.io/pip/3.6/get-pip.py | python3 -
912
RUN rm -rf $HOME/.cache
1013

1114
# ansible
12-
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc libffi-dev libssl-dev && \
15+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3-apt && \
1316
apt-get clean
14-
RUN pip install ansible==2.9.15
17+
RUN pip3 install ansible==2.10.7
1518
RUN rm -rf $HOME/.cache
1619

1720
# provision

meta/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# meta file
22
---
33
galaxy_info:
4-
namespace: oefenweb
4+
author: oefenweb
55
role_name: ssh_keys
6-
author: Mischa ter Smitten
76
company: Oefenweb.nl B.V.
87
description: Manage ssh public key authentication (public / private / authorized keys and known hosts) in Debian-like systems
98
license: MIT
10-
min_ansible_version: 2.9.0
9+
min_ansible_version: 2.10.0
1110
platforms:
1211
- name: Ubuntu
1312
versions:

molecule/default/collections.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
collections:
3+
- name: community.docker
4+
version: '>=1.2.0,<2'
5+
- name: community.general
6+
version: '>=2,<3'

requirements.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# requirements file
2+
---
3+
collections:
4+
- name: ansible.posix
5+
- name: community.crypto

tasks/authorized-keys.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tasks file
22
---
33
- name: authorized-keys | set up for users
4-
authorized_key:
4+
ansible.posix.authorized_key:
55
user: "{{ item.owner }}"
66
key: "{{ lookup('file', item.src) }}"
77
state: "{{ item.state | default('present') }}"

tasks/general.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tasks file
22
---
33
- name: general | create ssh directory
4-
file:
4+
ansible.builtin.file:
55
path: "{{ (item.dest_absolute | default('~' + item.owner + '/' + ssh_keys_sshdir + '/' + (item.dest | default(ssh_keys_private_key_filename)))) | dirname }}"
66
state: directory
77
owner: "{{ item.owner }}"
@@ -14,7 +14,7 @@
1414
- ssh-keys-general-create-ssh-directories-private-keys
1515

1616
- name: general | create ssh directory
17-
file:
17+
ansible.builtin.file:
1818
path: "~{{ item.owner }}/{{ ssh_keys_sshdir }}"
1919
state: directory
2020
owner: "{{ item.owner }}"

tasks/generate.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# tasks file
22
---
3-
- block:
3+
- name: generate
4+
block:
45

56
- name: generate | create ssh key generation directory
6-
file:
7+
ansible.builtin.file:
78
path: "{{ item.path | dirname }}"
89
owner: "{{ item.owner }}"
910
group: "{{ item.group | default(item.owner) }}"
@@ -14,17 +15,18 @@
1415
- ssh-keys-generate-directories
1516

1617
- name: generate | generate private ssh key
17-
shell: "{{ ssh_keys_generate_keys_command | default(_ssh_keys_generate_keys_command) }}"
18-
tags:
19-
- ssh-keys-generate-private-keys
20-
- skip_ansible_lint
18+
ansible.builtin.shell: >
19+
{{ ssh_keys_generate_keys_command | default(_ssh_keys_generate_keys_command) }}
20+
with_items: "{{ ssh_keys_generate_keys }}"
2121
when: >-
2222
item.force | default(false) | bool or
2323
item.path is not file
24-
with_items: "{{ ssh_keys_generate_keys }}"
24+
tags:
25+
- ssh-keys-generate-private-keys
26+
- skip_ansible_lint
2527

2628
- name: generate | set permissions on keys
27-
file:
29+
ansible.builtin.file:
2830
path: "{{ item.path }}"
2931
owner: "{{ item.owner }}"
3032
group: "{{ item.group | default(item.owner) }}"
@@ -34,7 +36,7 @@
3436
- ssh-keys-generate-permissions
3537

3638
- name: generate | generate public ssh key
37-
openssl_publickey:
39+
community.crypto.openssl_publickey:
3840
path: "{{ item.path }}.pub"
3941
force: "{{ item.force | default(false) }}"
4042
format: "{{ item.format | default('OpenSSH') }}"

tasks/known-hosts.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tasks file
22
---
33
- name: known-hosts | stat directories
4-
stat:
4+
ansible.builtin.stat:
55
path: "{{ item }}/"
66
register: _stat_directories
77
with_items:
@@ -11,7 +11,7 @@
1111
- ssh-keys-known-hosts-directories-stat
1212

1313
- name: known-hosts | create directories
14-
file:
14+
ansible.builtin.file:
1515
path: "{{ item.item }}"
1616
state: directory
1717
owner: root
@@ -24,7 +24,7 @@
2424
- ssh-keys-known-hosts-directories-create
2525

2626
- name: known-hosts | update file
27-
template:
27+
ansible.builtin.template:
2828
src: "{{ ssh_keys_known_hosts_path.lstrip('/') }}.j2"
2929
dest: "{{ ssh_keys_known_hosts_path }}"
3030
owner: root

tasks/main.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
# tasks file
22
---
3-
4-
- import_tasks: generate.yml
3+
- ansible.builtin.import_tasks: generate.yml
54
tags:
65
- configuration
76
- ssh-keys
87
- ssh-keys-generate
98

10-
- import_tasks: general.yml
9+
- ansible.builtin.import_tasks: general.yml
1110
tags:
1211
- configuration
1312
- ssh-keys
1413
- ssh-keys-general
1514

16-
- import_tasks: private-keys.yml
15+
- ansible.builtin.import_tasks: private-keys.yml
1716
tags:
1817
- configuration
1918
- ssh-keys
2019
- ssh-keys-private-keys
2120

22-
- import_tasks: public-keys.yml
21+
- ansible.builtin.import_tasks: public-keys.yml
2322
tags:
2423
- configuration
2524
- ssh-keys
2625
- ssh-keys-public-keys
2726

28-
- import_tasks: authorized-keys.yml
27+
- ansible.builtin.import_tasks: authorized-keys.yml
2928
tags:
3029
- configuration
3130
- ssh-keys
3231
- ssh-keys-authorized-keys
3332

34-
- import_tasks: known-hosts.yml
33+
- ansible.builtin.import_tasks: known-hosts.yml
3534
tags:
3635
- configuration
3736
- ssh-keys

tasks/private-keys.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tasks file
22
---
33
- name: private-keys | add
4-
copy:
4+
ansible.builtin.copy:
55
src: "{{ item.src }}"
66
dest: "{{ item.dest_absolute | default('~' + item.owner + '/' + ssh_keys_sshdir + '/' + (item.dest | default(ssh_keys_private_key_filename))) }}"
77
owner: "{{ item.owner }}"
@@ -13,7 +13,7 @@
1313
- ssh-keys-private-keys-add
1414

1515
- name: private-keys | remove
16-
file:
16+
ansible.builtin.file:
1717
path: "{{ item.dest_absolute | default('~' + item.owner + '/' + ssh_keys_sshdir + '/' + (item.dest | default(ssh_keys_private_key_filename))) }}"
1818
state: absent
1919
with_items: "{{ ssh_keys_private_keys }}"

tasks/public-keys.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tasks file
22
---
33
- name: public-keys | add
4-
copy:
4+
ansible.builtin.copy:
55
src: "{{ item.src }}"
66
dest: "{{ item.dest_absolute | default('~' + item.owner + '/' + ssh_keys_sshdir + '/' + (item.dest | default(ssh_keys_public_key_filename))) }}"
77
owner: "{{ item.owner }}"
@@ -13,7 +13,7 @@
1313
- ssh-keys-public-keys-add
1414

1515
- name: public-keys | remove
16-
file:
16+
ansible.builtin.file:
1717
path: "{{ item.dest_absolute | default('~' + item.owner + '/' + ssh_keys_sshdir + '/' + (item.dest | default(ssh_keys_public_key_filename))) }}"
1818
state: absent
1919
with_items: "{{ ssh_keys_public_keys }}"

tests/tasks/post.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# post test file
22
---
33
- name: set fact
4-
command: >
4+
ansible.builtin.command: >
55
echo "{{ ansible_connection }}"
66
register: _ansible_connection
77
changed_when: false
88

99
- block:
1010

1111
- name: test presence of private key
12-
shell: >
13-
diff {{ ssh_keys_private_keys[0]['src'] }} ~dummy/.ssh/{{ ssh_keys_private_keys[0]['src'] | basename }}
12+
ansible.builtin.shell: >
13+
diff {{ ssh_keys_private_keys[0]['src'] }} ~{{ ssh_keys_owner }}/.ssh/{{ ssh_keys_private_keys[0]['src'] | basename }}
1414
&& (echo 'Private key test: pass' && exit 0)
1515
|| (echo 'Private key test: fail' && exit 1)
1616
args:
@@ -20,8 +20,8 @@
2020
- skip_ansible_lint
2121

2222
- name: test presence of public key
23-
shell: >
24-
diff {{ ssh_keys_public_keys[0]['src'] }} ~dummy/.ssh/{{ ssh_keys_public_keys[0]['src'] | basename }}
23+
ansible.builtin.shell: >
24+
diff {{ ssh_keys_public_keys[0]['src'] }} ~{{ ssh_keys_owner }}/.ssh/{{ ssh_keys_public_keys[0]['src'] | basename }}
2525
&& (echo 'Public key test: pass' && exit 0)
2626
|| (echo 'Public key test: fail' && exit 1)
2727
args:
@@ -33,7 +33,7 @@
3333
- skip_ansible_lint
3434

3535
- name: test presence of known hosts
36-
shell: >
36+
ansible.builtin.shell: >
3737
grep -q 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa' /etc/ssh/ssh_known_hosts
3838
&& (echo 'Known hosts test: pass' && exit 0)
3939
|| (echo 'Known hosts test: fail' && exit 1)

tests/tasks/pre.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# pre test file
22
---
33
- name: install dependencies
4-
apt:
4+
ansible.builtin.apt:
55
name:
66
- openssh-client
77
state: "{{ apt_install_state | default('latest') }}"
88
update_cache: true
99
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
1010

1111
- name: generate key pair
12-
command: >
12+
ansible.builtin.command: >
1313
ssh-keygen -t rsa -b 2048 -C '' -P '' -f {{ ssh_keys_private_key }} -q
1414
args:
1515
creates: "{{ ssh_keys_private_key }}"
1616
connection: local
1717
become: false
1818

1919
- name: create user (if needed)
20-
user:
21-
name: dummy
20+
ansible.builtin.user:
21+
name: "{{ ssh_keys_owner }}"

tests/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
become: true
66
pre_tasks:
77
- name: include vars
8-
include_vars: "{{ playbook_dir }}/vars/main.yml"
8+
ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml"
99
- name: include tasks
10-
include: "{{ playbook_dir }}/tasks/pre.yml"
10+
ansible.builtin.include: "{{ playbook_dir }}/tasks/pre.yml"
1111
roles:
1212
- ../../
1313
post_tasks:
1414
- name: include tasks
15-
include: "{{ playbook_dir }}/tasks/post.yml"
15+
ansible.builtin.include: "{{ playbook_dir }}/tasks/post.yml"

tests/vagrant.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
become: true
66
pre_tasks:
77
- name: include vars
8-
include_vars: "{{ playbook_dir }}/vars/main.yml"
8+
ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml"
99
- name: include tasks
10-
include: "{{ playbook_dir }}/tasks/pre.yml"
10+
ansible.builtin.include: "{{ playbook_dir }}/tasks/pre.yml"
1111
roles:
1212
- ../../
1313
post_tasks:
1414
- name: include tasks
15-
include: "{{ playbook_dir }}/tasks/post.yml"
15+
ansible.builtin.include: "{{ playbook_dir }}/tasks/post.yml"

tests/vars/main.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# vars file
22
---
3+
ssh_keys_owner: dummy
34
ssh_keys_private_keys:
4-
- owner: dummy
5+
- owner: "{{ ssh_keys_owner }}"
56
src: "{{ ssh_keys_private_key }}"
67
ssh_keys_public_keys:
7-
- owner: dummy
8+
- owner: "{{ ssh_keys_owner }}"
89
src: "{{ ssh_keys_private_key }}.pub"
910
ssh_keys_authorized_keys:
10-
- owner: dummy
11+
- owner: "{{ ssh_keys_owner }}"
1112
src: "{{ ssh_keys_private_key }}.pub"
1213
ssh_keys_known_hosts:
1314
- hostname: github.com

0 commit comments

Comments
 (0)