diff --git a/roles/add-fileserver/README.rst b/roles/add-fileserver/README.rst new file mode 100644 index 000000000..cd7a0cf06 --- /dev/null +++ b/roles/add-fileserver/README.rst @@ -0,0 +1,34 @@ +Add a remote fileserver to the inventory so that content can be uploaded +in subsequent tasks or roles. + +**Role Variables** + +.. zuul:rolevar:: fileserver + + Complex argument which contains the information about the remote + destination as well as the authentication information needed. It is + expected that this argument comes from a `Secret`. + + .. zuul:rolevar:: fqdn + + The FQDN of the remote host. + + .. zuul:rolevar:: path + + The remote path. Content will be put into a directory below this path + that matches ``zuul.project.short_name``. The full path including + the project short name will be added to the hostvars of the host + as ``zuul_fileserver_project_path``. + + .. zuul:rolevar:: ssh_known_hosts + + String containing known host signature for the remote host. + + .. zuul:rolevar:: ssh_private_key + + Contents of the ssh private key to use. + + .. zuul:rolevar:: ssh_username + :default: ansible_user + + Remote ssh user name to use. diff --git a/roles/add-fileserver/tasks/main.yaml b/roles/add-fileserver/tasks/main.yaml index e5365bbd8..c5a021fbf 100644 --- a/roles/add-fileserver/tasks/main.yaml +++ b/roles/add-fileserver/tasks/main.yaml @@ -1,21 +1,22 @@ - name: Create SSH private key from secret copy: content: "{{ fileserver.ssh_private_key }}" - dest: ~/.ssh/tarballs_id_rsa + dest: ~/.ssh/fileserver_id_rsa mode: 0600 -- name: Add tarballs server ssh key - command: ssh-add ~/.ssh/tarballs_id_rsa +- name: Add fileserver ssh key + command: ssh-add ~/.ssh/fileserver_id_rsa - name: Remove SSH private key from disk - command: shred ~/.ssh/tarballs_id_rsa + command: shred ~/.ssh/fileserver_id_rsa -- name: Add tarballs server to inventory +- name: Add fileserver to inventory add_host: name: "{{ fileserver.fqdn }}" - ansible_user: "{{ fileserver.ssh_username }}" + ansible_user: "{{ fileserver.ssh_username|default(ansible_user) }}" + zuul_fileserver_project_path: "{{ fileserver.path }}/{{ zuul.project.short_name }}" -- name: Add tarballs server to known hosts +- name: Add fileserver server to known hosts known_hosts: name: "{{ fileserver.fqdn }}" key: "{{ fileserver.ssh_known_hosts }}" diff --git a/roles/publish-artifacts-to-fileserver/README.rst b/roles/publish-artifacts-to-fileserver/README.rst new file mode 100644 index 000000000..beb046bc7 --- /dev/null +++ b/roles/publish-artifacts-to-fileserver/README.rst @@ -0,0 +1,15 @@ +Publish contents of ``{{ zuul.executor.work_root }}/artifacts/`` dir using +rsync over ssh to a remote fileserver that has previously been added to +the inventory by :zuul:role:`add-fileserver`. + +**Role Variables** + +:zuul:role:`add-fileserver` sets the following variable in the hostvars of the +hosts it adds, but it is documented for reference. + +.. zuul:rolevar:: zuul_fileserver_project_path + + The remote path. Content will be put into a directory below this path + that matches ``zuul.project.short_name``. The full path including + the project short name will be added to the hostvars of the host + as ``zuul_fileserver_project_path``. diff --git a/roles/publish-artifacts-to-fileserver/tasks/main.yaml b/roles/publish-artifacts-to-fileserver/tasks/main.yaml index 933bb29e7..4f53e7bfe 100644 --- a/roles/publish-artifacts-to-fileserver/tasks/main.yaml +++ b/roles/publish-artifacts-to-fileserver/tasks/main.yaml @@ -1,10 +1,6 @@ -- name: Set tarball path - set_fact: - tarball_path: "{{ fileserver.path }}/{{ zuul.project.short_name }}" - -- name: Ensure project directory exists +- name: Ensure project artifact directory exists file: - path: "{{ tarball_path }}" + path: "{{ zuul_fileserver_project_path }}" state: directory recurse: yes mode: 0775 @@ -12,4 +8,4 @@ - name: Upload contents of the artifacts folder synchronize: src: "{{ zuul.executor.work_root }}/artifacts/" - dest: "{{ tarball_path }}/" + dest: "{{ zuul_fileserver_project_path }}/"