diff --git a/ansible/deploy.yaml b/ansible/deploy.yaml index b4b9d2d92f6cacaa4a1ea75b1ed5f4af84c5a25e..d2f965dfb8da0bf36240170fc90a6bfdd93c06f0 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 525948e753bd591f571ed4dca76d40e6e3f1cfb6..627a1b60c3cb5c61e2650876705f7b5274c40248 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 0000000000000000000000000000000000000000..81d0ac74b994051319b17da12ebf899d5fbc8b9d --- /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 1e792568d803145ff7f23c31120b72471818591f..00b326f3abed67c2bdc59397290bf4e442105b0b 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