diff --git a/deploy_ovh_instance.yml b/deploy_ovh_instance.yml index 9490659..f9aa277 100644 --- a/deploy_ovh_instance.yml +++ b/deploy_ovh_instance.yml @@ -48,7 +48,7 @@ - always - name: Remove old SSH host key - command: ssh-keygen -f "/home/{{ LINUX_USERNAME }}/.ssh/known_hosts" -R "{{ item }}" + command: ssh-keygen -f "{{ ansible_user_dir }}/.ssh/known_hosts" -R "{{ item }}" changed_when: false with_items: - "{{ target_name }}" @@ -109,9 +109,15 @@ - common - always + - name: Gather facts + ansible.builtin.setup: + tags: + - common + - always + - name: set remote workdir path ansible.builtin.set_fact: - remote_workdir: "/home/{{ ansible_user }}/{{ ANSIBLE_WORKDIR }}" + remote_workdir: "{{ ansible_user_dir }}/{{ ANSIBLE_WORKDIR }}" tags: - common - always diff --git a/roles/role_configure_ovh_instance/tasks/main.yml b/roles/role_configure_ovh_instance/tasks/main.yml index b00a7e7..3810c35 100644 --- a/roles/role_configure_ovh_instance/tasks/main.yml +++ b/roles/role_configure_ovh_instance/tasks/main.yml @@ -261,17 +261,20 @@ set_fact: ansible_user: "{{ LINUX_USERNAME }}" +- name: Gather facts + ansible.builtin.setup: + # Those will deploy SSH keys found on the Ansible controller - name: Deploy SSH private key copy: src: "{{ PRIVATE_KEY_FILE }}" - dest: "/home/{{ LINUX_USERNAME }}/.ssh/" + dest: "/{{ ansible_user_dir }}/.ssh/" mode: 0600 - name: Deploy SSH public key copy: src: "{{ PUBLIC_KEY_FILE }}" - dest: "/home/{{ LINUX_USERNAME }}/.ssh/" + dest: "/{{ ansible_user_dir }}/.ssh/" mode: 0640 - name: Configure VIM @@ -338,12 +341,12 @@ - name: user.email value: "{{ git_email }}" -- name: Create /home/{{ LINUX_USERNAME }}/.bashrc.d directory +- name: Create {{ ansible_user_dir }}/.bashrc.d directory ansible.builtin.file: - path: "/home/{{ LINUX_USERNAME }}/.bashrc.d" + path: "{{ ansible_user_dir }}/.bashrc.d" state: directory - name: deploy .bashrc.d/tmux ansible.builtin.copy: src: tmux - dest: "/home/{{ LINUX_USERNAME }}/.bashrc.d/tmux" + dest: "{{ ansible_user_dir }}/.bashrc.d/tmux" diff --git a/vars/main.yml b/vars/main.yml index 552d0f9..b2275ef 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -10,6 +10,7 @@ SWIFT_REGIONNAME: "GRA" LINUX_USERNAME: "yohan" +# Path of SSH key pair on Ansible controller PRIVATE_KEY_FILE: "/home/{{ LINUX_USERNAME }}/.ssh/id_rsa" PUBLIC_KEY_FILE: "/home/{{ LINUX_USERNAME }}/.ssh/id_rsa.pub"