From 9e862d8c5699cc0bab51e61ac63401fda5a1695c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Thu, 13 Jul 2017 18:14:18 +0200 Subject: [PATCH] [WIP] ansible deployment system works up until gitlab upload current error is a 404: ``` [hmenager@hub16 tmp]$ sudo curl -X POST -H 'Accept: sudo application/json' -H 'Content-type: application/json' -H 'PRIVATE-TOKEN: xxxxxxxxxxxxxx' --data-binary @/home/ippidb/ssh_key.json https://gitlab.pasteur.fr/api/v3/projects/odoppelt/iPPIDB/keys {"error":"404 Not Found"} ``` Former-commit-id: 73839d6d0f1d8b10cb28c5f277115215dbc57e0e --- ansible/deploy.yaml | 7 +++---- ansible/hosts | 2 +- ansible/ssh_key.json.j2 | 1 + ansible/system.yaml | 30 ++++++++++++++++++++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 ansible/ssh_key.json.j2 diff --git a/ansible/deploy.yaml b/ansible/deploy.yaml index b4b9d2d9..d2f965df 100644 --- a/ansible/deploy.yaml +++ b/ansible/deploy.yaml @@ -1,14 +1,13 @@ --- - hosts: all become: yes - become_user: ubuntu + become_user: ippidb gather_facts: no - tasks: - name: pull branch master git: - repo={{ repo_url }}/{{ repo }}.git - dest={{ repo_dir }} + repo=git@gitlab.pasteur.fr:odoppelt/iPPIDB.git + dest=iPPIDB accept_hostkey=yes - hosts: all diff --git a/ansible/hosts b/ansible/hosts index 525948e7..627a1b60 100644 --- a/ansible/hosts +++ b/ansible/hosts @@ -1 +1 @@ -ippidb +ippidb.pasteur.fr diff --git a/ansible/ssh_key.json.j2 b/ansible/ssh_key.json.j2 new file mode 100644 index 00000000..81d0ac74 --- /dev/null +++ b/ansible/ssh_key.json.j2 @@ -0,0 +1 @@ +{"id": "odoppelt/iPPIDB","title" : "{ippidb_deploy_key","key": "{{ key_value.stdout }}"} diff --git a/ansible/system.yaml b/ansible/system.yaml index 1e792568..00b326f3 100644 --- a/ansible/system.yaml +++ b/ansible/system.yaml @@ -2,9 +2,27 @@ - hosts: all gather_facts: no tasks: - - name: Create ippidb user - user: name=ippidb generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa - - name: Read SSH public key - slurp: src=/home/ippidb/.ssh/id_rsa.pub - register: public_key - - debug: msg="{{ public_key['content'] | b64decode }}" + - name: Create {{ deploy_user_name }} user + user: name={{ deploy_user_name }} generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa + become: true + #- name: Read SSH public key + # slurp: src=/home/ippidb/.ssh/id_rsa.pub + # register: public_key + # become: true + #- debug: msg="{{ public_key['content'] | b64decode }}" + - name: install git + yum: name=git state=present + become: true + - name: Cat deployer's user public key + shell: "cat /home/{{ deploy_user_name }}/.ssh/id_rsa.pub" + register: key_value + become: true + - name: Create ssh_key json + template: src=ssh_key.json.j2 dest=/home/{{ deploy_user_name }}/ssh_key.json group={{ deploy_user_name }} owner={{ deploy_user_name }} force=yes + become: true + - name: Cat deployer's user public key + shell: "cat /home/{{ deploy_user_name }}/ssh_key.json" + become: true + - name: Upload deploy keys to gitlab + shell: "curl -X POST -H 'Accept: application/json' -H 'Content-type: application/json' -H 'PRIVATE-TOKEN: {{ repo_api_token }}' --data-binary @/home/{{ deploy_user_name }}/ssh_key.json https://gitlab.pasteur.fr/api/v3/projects/odoppelt/iPPIDB/keys" + become: true -- GitLab