Skip to content

Commit

Permalink
[IMP] New options 'odoo_user_ssh_key' and 'odoo_user_ssh_known_hosts'…
Browse files Browse the repository at this point in the history
… to configure SSH private (without passphrase) and public keys with the Odoo user allowing to clone private Git/Mercurial repositories (via the 'odoo_repo_url' or indirectly with 'buildout' install type)
  • Loading branch information
sebalix committed Mar 28, 2018
1 parent 31b3907 commit 4e5934c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 16 deletions.
21 changes: 19 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,22 @@ odoo_buildout_odoo_bin_path: "{{ odoo_workdir }}/bin/start_odoo"
odoo_buildout_extra_dependencies: [] # Extra Debian packages required
# to run your Buildout recipe

# Extra options
odoo_user_sshkeys: "" # ../../path/to/public_keys/*
# SSH configuration options
odoo_user_ssh_dir: "/home/{{ odoo_user }}/.ssh"
odoo_user_ssh_key: {}
# This option set only a pair of private key (/!\ without password /!\)
# and public key saved as 'id_rsa{.pub}' (default path) allowing version
# control like Git to clone repositories without configuring the ssh-agent.
# Example:
# odoo_user_ssh_key:
# priv: "path/to/private_key"
# pub: "path/to/public_key.pub"
odoo_user_ssh_known_hosts_file: "{{ odoo_user_ssh_dir }}/known_hosts"
odoo_user_ssh_known_hosts: []
# This option add hosts fingerprint to the 'known_hosts' file. Example:
# odoo_user_ssh_known_hosts:
# - bitbucket.org
#
# FIXME: 'odoo_user_sshkeys' option (and the underlying task) needs refactoring
# to handle the state of SSH public keys (present/absent).
odoo_user_sshkeys: "" # ./path/to/public_keys/*
10 changes: 5 additions & 5 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
tags:
- odoo_user

- name: Configure SSH for the Odoo user
import_tasks: install_ssh.yml
tags:
- odoo_install_ssh

- name: Create log directory
file: path={{ odoo_logdir }} state=directory
owner={{ odoo_user }} group={{ odoo_user }} force=no
Expand Down Expand Up @@ -86,8 +91,3 @@
tags:
- odoo
- odoo_packages

- import_tasks: install_extra.yml
when: odoo_user_sshkeys is defined and odoo_user_sshkeys
tags:
- odoo_install_extra
9 changes: 0 additions & 9 deletions tasks/install_extra.yml

This file was deleted.

54 changes: 54 additions & 0 deletions tasks/install_ssh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---

- block:

- name: SSH - Install private and public keys for the Odoo user
copy:
src: "{{ item.value }}"
dest: "{{ odoo_user_ssh_dir }}/id_rsa{{ '.pub' if item.key == 'pub' else '' }}"
mode: "{{ '0600' if item.key == 'priv' else '0644' }}"
with_dict: "{{ odoo_user_ssh_key }}"

- name: SSH - Remove private and public keys if none is defined
file:
path: "{{ item }}"
state: absent
with_list:
- "{{ odoo_user_ssh_dir }}/id_rsa"
- "{{ odoo_user_ssh_dir }}/id_rsa.pub"
when: not odoo_user_ssh_key

- name: SSH - Make sure the SSH directory exists
file:
path: "{{ odoo_user_ssh_dir }}"
state: directory
mode: 0700
changed_when: no

- name: SSH - Make sure the known_hosts file exists
file:
path: "{{ odoo_user_ssh_known_hosts_file }}"
state: touch
changed_when: no

- name: SSH - Check host name availability in the known hosts file
shell: "ssh-keygen -f {{ odoo_user_ssh_known_hosts_file }} -F {{ item }}"
with_items: "{{ odoo_user_ssh_known_hosts }}"
register: odoo_user_ssh_known_host_results
ignore_errors: yes
changed_when: no

- name: SSH - Scan hosts public keys
shell: "{{ odoo_ssh_keyscan_cmd}} {{ item.item }} >> {{ odoo_user_ssh_known_hosts_file }}"
when: item.stdout == ""
with_items: "{{ odoo_user_ssh_known_host_results.results }}"

- name: Set SSH public keys for the Odoo user
authorized_key:
user: "{{ odoo_user }}"
key: "{{ lookup('file', item) }}"
with_fileglob:
- "{{ odoo_user_sshkeys }}"

become: yes
become_user: "{{ odoo_user }}"
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ odoo_nodejs_apt_repositories:
odoo_nodejs_apt_keys:
- url: http://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present

# SSH
odoo_ssh_keyscan_cmd: "ssh-keyscan -H -T 10"

0 comments on commit 4e5934c

Please sign in to comment.