Skip to content

Commit

Permalink
Credentials updated
Browse files Browse the repository at this point in the history
Signed-off-by: Bas Meijer <[email protected]>
  • Loading branch information
bbaassssiiee committed Dec 4, 2024
1 parent 04e83a3 commit c080289
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
2 changes: 2 additions & 0 deletions roles/api/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ debug: false
desired_state: present
# Create an SSH key to download private repos from GitHub
my_github_key: ~/.ssh/github_key
inventory_key: ~/.vagrant.d/insecure_private_keys/vagrant.key.ed25519
inventory_user: vagrant
controller_repository_name: controller
controller_repository_git_url: 'https://github.com/playingfield/controller'
controller_repository_git_branch: main
3 changes: 2 additions & 1 deletion roles/api/tasks/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
status_code: 200
timeout: 5
register: semaphore_projects
no_log: "{{ not debug }}"

- name: "Create Project"
- name: "Create Controller Project"
changed_when: "semaphore_project_created.status == 201"
ansible.builtin.uri:
use_proxy: false
Expand Down
3 changes: 2 additions & 1 deletion roles/api/tasks/cookie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
no_log: "{{ not debug }}"

- name: Save Cookie
when: login_response.status == 204
ansible.builtin.set_fact:
cookie: "{{ login_response.cookies_string }}"
when: login_response.status == 204
no_log: "{{ not debug }}"
45 changes: 42 additions & 3 deletions roles/api/tasks/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
headers:
Cookie: "{{ cookie }}"
status_code: 200
no_log: "{{ not debug }}"
register: semaphore_keystores

- name: Create SSH key for Controller
- name: Key Store - Controller
changed_when: "semaphore_key_ansible_created.status == 204"
ansible.builtin.uri:
url: "{{ semaphore_api_url }}/project/{{ semaphore_project_id }}/keys"
Expand All @@ -50,7 +51,7 @@
when:
- "semaphore_keystores.json | selectattr('name', 'equalto', 'Controller-ssh-key') | length == 0"

- name: Read ssh key from system
- name: Read ssh key for GitHub
delegate_to: localhost
connection: local
become: false
Expand All @@ -60,7 +61,7 @@
register: "ssh_key_github"
failed_when: false

- name: Create SSH key for GitHub
- name: Key Store - GitHub
changed_when: "semaphore_key_github_created.status == 204"
ansible.builtin.uri:
use_proxy: false
Expand All @@ -86,3 +87,41 @@
when:
- ssh_key_github.content is defined
- "semaphore_keystores.json | selectattr('name', 'equalto', 'github-ssh-key') | length == 0"

- name: Read ssh_key_inventory for inventory_user
delegate_to: localhost
connection: local
become: false
no_log: "{{ not debug }}"
ansible.builtin.slurp:
path: "{{ inventory_key }}"
register: "ssh_key_inventory"
failed_when: false

- name: "Key Store - {{ inventory_user}}-ssh-key"
changed_when: "semaphore_key_inventory_created.status == 204"
ansible.builtin.uri:
use_proxy: false
url: "{{ semaphore_api_url }}/project/{{ semaphore_project_id }}/keys"
method: POST
headers:
Cookie: "{{ cookie }}"
body: >-
{
"project_id": {{ semaphore_project_id | int }},
"name": "{{ inventory_user}}-ssh-key",
"type": "ssh",
"login": "{{ inventory_user }}",
"ssh":
{
"private_key": {{ ssh_key_inventory.content | b64decode | to_json }}
}
}
body_format: json
status_code: 204
timeout: 5
no_log: "{{ not debug }}"
register: semaphore_key_inventory_created
when:
- ssh_key_inventory.content is defined
- "semaphore_keystores.json | selectattr('name', 'equalto', inventory_user ~ '-ssh-key') | length == 0"

0 comments on commit c080289

Please sign in to comment.