Skip to content

Commit

Permalink
Merge pull request #5 from idealista/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
jmonterrubio authored Jul 6, 2017
2 parents 336c775 + 820f2ac commit 582ec55
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

## [Unreleased](https://github.com/idealista/aptly-role/tree/develop)

## [1.1.0](https://github.com/idealista/aptly-role/tree/1.1.0) (2017-07-06)

### Added
- *[#2](https://github.com/idealista/aptly-role/issues/2) Enable api* @jmonterrubio

## [1.0.0](https://github.com/idealista/aptly-role/tree/1.0.0) (2017-06-28)

Expand Down
3 changes: 1 addition & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ aptly_group: aptly
# Host& Port
aptly_host: 127.0.0.1
aptly_port: 8001
aptly_api_port: 8002

# start on boot
aptly_service_enabled: yes
Expand All @@ -20,8 +21,6 @@ aptly_service_state: started

# Files & Paths
aptly_install_path: "/opt/aptly"
aptly_conf_path: "/etc/aptly"
aptly_log_path: "/var/log/aptly"
aptly_packages_path: "/var/www/repositories"

## Miscellaneous
Expand Down
6 changes: 6 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
name: aptly
state: restarted
when: aptly_service_state != 'stopped'

- name: restart aptly-api
systemd:
name: aptly-api
state: restarted
when: aptly_service_state != 'stopped'
16 changes: 11 additions & 5 deletions tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
group: "{{ aptly_group }}"
recurse: yes
with_items:
- "{{ aptly_conf_path }}"
- "{{ aptly_log_path }}"
- "{{ aptly_packages_path }}"
- "{{ aptly_gpg_path }}"

- name: APTLY | Copy config
template:
src: aptly.conf.j2
dest: "{{ aptly_conf_path }}/aptly.conf"
dest: /etc/aptly.conf
mode: 0640
owner: "{{ aptly_user }}"
group: "{{ aptly_group }}"
Expand All @@ -30,13 +28,19 @@
owner: "{{ aptly_user }}"
group: "{{ aptly_group }}"

- name: APTLY | Set key query
set_fact:
the_query: gpg --list-keys | grep 'pub ' | tail -1 | sed 's/pub 2048D\///g' | cut -d' ' -f1

- name: APTLY | Obtain last key id
shell: bash -lc "gpg --list-keys | grep 'pub ' | tail -1 | sed 's/pub 2048D\///g' | cut -d' ' -f1"
shell: bash -lc "{{ the_query }}"
become_user: "{{ aptly_user }}"
become: true
changed_when: false
register: aptly_key_info
ignore_errors: true
tags:
skip_ansible_lint
##gpg --list-keys
##/home/aptly/.gnupg/pubring.gpg
##------------------------------
Expand All @@ -57,11 +61,13 @@
when: aptly_key_info|failed or aptly_key_info.stdout == ""

- name: APTLY | Obtain last key id
shell: bash -lc "gpg --list-keys | grep 'pub ' | tail -1 | sed 's/pub 2048D\///g' | cut -d' ' -f1"
shell: bash -lc "{{ the_query }}"
become_user: "{{ aptly_user }}"
become: true
register: aptly_key_info_new
when: aptly_key_info|failed or aptly_key_info.stdout == ""
tags:
skip_ansible_lint

- name: APTLY | Export key
shell: gpg --export -a {{ aptly_user }} > {{ aptly_gpg_path }}/public.key
Expand Down
13 changes: 13 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@
dest: "{{ aptly_install_path }}"
owner: "{{ aptly_user }}"
group: "{{ aptly_group }}"
mode: 0750
when: 'aptly_force_reinstall or aptly_check|failed or aptly_check.stdout == "{{ aptly_version }}"'

- name: APTLY | Enable binary execution
file:
path: "{{ aptly_install_path }}/aptly"
mode: 0755

- name: APTLY | Link binary
file:
src: "{{ aptly_install_path }}/aptly"
Expand All @@ -53,3 +59,10 @@
dest: /lib/systemd/system/aptly.service
mode: 0644
notify: restart aptly

- name: APTLY | Copy Daemon script (API)
template:
src: aptly-api.service.j2
dest: /lib/systemd/system/aptly-api.service
mode: 0644
notify: restart aptly-api
17 changes: 12 additions & 5 deletions tasks/repositories.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---

# Needed because a bug when api is started -> ERROR: can't open database:
- name: APTLY | Stop service (API)
systemd:
name: aptly-api
state: stopped
changed_when: false

- name: APTLY | Obtain created repos
command: aptly repo list -raw -config={{ aptly_conf_path }}/aptly.conf
command: aptly repo list -raw -config=/etc/aptly.conf
become_user: "{{ aptly_user }}"
become: true
changed_when: false
Expand All @@ -10,7 +17,7 @@
- name: APTLY | Create repositories
command: >
aptly repo create
-config={{ aptly_conf_path }}/aptly.conf
-config=/etc/aptly.conf
-distribution={{ aptly_repositories_distribution }}
-component=main
{{ item }}
Expand All @@ -23,7 +30,7 @@
skip_ansible_lint

- name: APTLY | Obtain published repos
shell: bash -lc "aptly publish list -raw -config={{ aptly_conf_path }}/aptly.conf | cut -d' ' -f1"
shell: bash -lc "aptly publish list -raw -config=/etc/aptly.conf | cut -d' ' -f1"
become_user: "{{ aptly_user }}"
become: true
changed_when: false
Expand All @@ -32,15 +39,15 @@
- name: APTLY | Publish repositories
command: >
aptly publish repo
-config={{ aptly_conf_path }}/aptly.conf
-config=/etc/aptly.conf
-component=main
-gpg-key={{ aptly_key_id }}
{{ item }}
{{ item }}
become_user: "{{ aptly_user }}"
become: true
ignore_errors: yes
with_items: "{{ aptly_repositories | difference(aptly_repo_list.stdout_lines) }}"
with_items: "{{ aptly_repositories | difference(aptly_publish_list.stdout_lines) }}"
notify: restart aptly
tags:
skip_ansible_lint
8 changes: 8 additions & 0 deletions tasks/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
state: "{{ aptly_service_state }}"
enabled: "{{ aptly_service_enabled }}"
daemon_reload: yes

- name: APTLY | Configuring service (API)
systemd:
name: aptly-api
state: "{{ aptly_service_state }}"
enabled: "{{ aptly_service_enabled }}"
daemon_reload: yes
changed_when: false
13 changes: 13 additions & 0 deletions templates/aptly-api.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Aptly API Debian repository management
After=network.target

[Service]
Type=simple
RuntimeDirectory=aptly
ExecStart=/usr/bin/aptly api serve -config=/etc/aptly.conf -listen={{ aptly_host }}:{{ aptly_api_port }}
ExecStop=/bin/kill -s QUIT $MAINPID
User={{ aptly_user }}

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion templates/aptly.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=network.target
[Service]
Type=simple
RuntimeDirectory=aptly
ExecStart=/usr/bin/aptly serve -config={{ aptly_conf_path }}/aptly.conf -listen={{ aptly_host }}:{{ aptly_port }}
ExecStart=/usr/bin/aptly serve -config=/etc/aptly.conf -listen={{ aptly_host }}:{{ aptly_port }}
ExecStop=/bin/kill -s QUIT $MAINPID
User={{ aptly_user }}

Expand Down
5 changes: 3 additions & 2 deletions tests/group_vars/aptly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
aptly_email: test@idealista.com

aptly_repositories:
- testing
aptly_repositories_distribution: jessie
- release
- snapshot
aptly_repositories_distribution: stretch
24 changes: 10 additions & 14 deletions tests/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@ def AnsibleVars(Ansible):
return Ansible("include_vars", "tests/group_vars/aptly.yml")["ansible_facts"]


def test_kafka_user(User, Group, AnsibleDefaults):
def test_aptly_user(User, Group, AnsibleDefaults):
assert User(AnsibleDefaults["aptly_user"]).exists
assert Group(AnsibleDefaults["aptly_group"]).exists


def test_kafka_conf(File, AnsibleDefaults):
conf_dir = File(AnsibleDefaults["aptly_conf_path"])
conf_file = File(AnsibleDefaults["aptly_conf_path"] + "/aptly.conf")
assert conf_dir.exists
assert conf_dir.is_directory
assert conf_dir.user == AnsibleDefaults["aptly_user"]
assert conf_dir.group == AnsibleDefaults["aptly_group"]
assert conf_file.exists
assert conf_file.is_file
assert conf_file.user == AnsibleDefaults["aptly_user"]
assert conf_file.group == AnsibleDefaults["aptly_group"]


def test_aptly_service(File, Service, Socket, AnsibleDefaults):
host = AnsibleDefaults["aptly_host"]
port = AnsibleDefaults["aptly_port"]
Expand All @@ -38,6 +25,15 @@ def test_aptly_service(File, Service, Socket, AnsibleDefaults):
assert Socket("tcp://" + host + ":" + str(port)).is_listening


def test_aptly_api_service(File, Service, Socket, AnsibleDefaults):
host = AnsibleDefaults["aptly_host"]
port = AnsibleDefaults["aptly_api_port"]
assert File("/lib/systemd/system/aptly-api.service").exists
assert Service("aptly-api").is_enabled
assert Service("aptly-api").is_running
assert Socket("tcp://" + host + ":" + str(port)).is_listening


def test_aptly_version(Command, AnsibleDefaults):
aptly_version = AnsibleDefaults["aptly_version"]
command = Command("aptly version")
Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
required_libs:
- haveged
- graphviz

aptly_mirror: "https://bintray.com/artifact/download/smira/aptly"
aptly_package_name: "aptly_{{ aptly_version }}_{{ aptly_dist }}"
Expand Down

0 comments on commit 582ec55

Please sign in to comment.