Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate and install SSH key #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- include_vars:
file: certs.yml
failed_when: false
- include_vars:
file: ssh_keys.yml
failed_when: false
roles:
- foreman_ca
- foreman_certs
Expand Down
2 changes: 2 additions & 0 deletions roles/foreman_proxy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foreman_proxy_remote_execution_ssh_dir: /var/lib/foreman-proxy/ssh
foreman_proxy_remote_execution_ssh_keypair_name: id_rsa_foreman_proxy
79 changes: 79 additions & 0 deletions roles/foreman_proxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
name: rubygem-smart_proxy_ansible
state: latest

- name: 'Install smart_proxy_ansible'
yum:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required, but I did bad using yum earlier and not package

name: rubygem-smart_proxy_remote_execution_ssh
state: latest

- name: 'Settings file'
template:
src: settings.yml.j2
Expand Down Expand Up @@ -46,6 +51,79 @@
content: "{{ foreman_proxy_client_ca }}"
dest: /etc/foreman-proxy/foreman_ssl_ca.pem

- name: 'Create identity directory'
file:
path: "{{ foreman_proxy_remote_execution_ssh_dir }}"
state: directory
mode: '0700'
owner: foreman-proxy
group: foreman-proxy

- name: 'Symlink proxy home .ssh to identity directory'
file:
dest: "/usr/share/foreman-proxy/.ssh"
src: "{{ foreman_proxy_remote_execution_ssh_dir }}"
owner: foreman-proxy
group: foreman-proxy
state: link

- name: Generate /etc/ssh/ RSA host key
command: 'ssh-keygen -q -t rsa -b 4096 -f {{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }} -C "Foreman Remote execuction key" -N ""'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also let you drop the next two file tasks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp, I see further down below you already had that thought.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move it before these command so thats more obvious reading top-bottom

args:
creates: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}"

- name: 'Set correct owner on private key'
file:
owner: foreman-proxy
group: foreman-proxy
path: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}"

- name: 'Set correct owner on public key'
file:
owner: foreman-proxy
group: foreman-proxy
path: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}.pub"

# ansible 2.8 only
#- name: 'Create key pair'
# openssh_keypair:
# comment: "Foreman Remote execuction key"
# group: foreman-proxy
# owner: foreman-proxy
# path: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}"
# size: 4096
# type: rsa

- name: 'Read REX SSH private key'
slurp:
src: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}"
register: foreman_rex_ssh_private_key


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly nitpick extra line here.

- name: 'Read REX SSH public key'
slurp:
src: "{{ foreman_proxy_remote_execution_ssh_dir }}/{{ foreman_proxy_remote_execution_ssh_keypair_name }}.pub"
register: foreman_rex_ssh_public_key

- set_fact:
rex_ssh_keys: {
public: "{{ foreman_rex_ssh_public_key.content | b64decode }}",
private: "{{ foreman_rex_ssh_private_key.content | b64decode }}"
}

- name: 'Write ssh keys file'
copy:
content: "{{ rex_ssh_keys | to_nice_yaml }}"
dest: ssh_keys.yml
mode: 0600
delegate_to: localhost

- name: 'Install REX public key to authorized keys for root'
authorized_key:
comment: Foreman Remote execuction key
key: "{{ rex_ssh_keys.public }}"
user: root

- name: 'Start foreman-proxy'
service:
name: foreman-proxy
Expand All @@ -67,3 +145,4 @@

- name: 'Register'
command: "ansible-playbook /etc/foreman-proxy/register.yaml -e foreman_admin_password={{ foreman_admin_password }}"

2 changes: 1 addition & 1 deletion roles/foreman_setup/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: 'Registration playbook'
- name: 'Host registration playbook'
copy:
src: templates/register.yaml
dest: /etc/foreman/register.yaml
Expand Down