juju: a bit more elaborate login process

Change-Id: I77bbf5b94dbbdb37d6b168fbec055a73e99e8205
diff --git a/playbooks/setup-juju-client/pre.yaml b/playbooks/setup-juju-client/pre.yaml
index 0f2f4e7..2932385 100644
--- a/playbooks/setup-juju-client/pre.yaml
+++ b/playbooks/setup-juju-client/pre.yaml
@@ -6,6 +6,22 @@
     become: true
 
   - name: Log In to the Controller
-    ansible.builtin.shell:
-      cmd: echo -e "y\n{{ juju_secret['the_secret'] }}\n" | juju login 10.40.2.2:17070 --controller maas-controller --user zuul-nodepool-zaza
-      executable: /usr/bin/bash
+    block:
+      - name: Log in
+        ansible.builtin.shell: juju login 10.40.2.2:17070 --controller maas-controller --user zuul-nodepool-zaza
+        args:
+          stdin: "y\n{{ juju_secret['the_secret'] }}\n"
+
+      - name: Enter our password a second time
+        ansible.builtin.shell: juju clouds
+        args:
+          stdin: "{{ juju_secret['the_secret'] }}\n"
+
+      - name: Grab the Ansible credentials
+        ansible.builtin.shell: juju credentials --controller maas-controller --format yaml --show-secrets
+        register: juju_credentials_full
+
+      - name: Store them into a file
+        ansible.builtin.copy:
+          dest: /home/ubuntu/.local/share/juju/credentials.yaml
+          content: "credentials:\n{{ juju_credentials_full.stdout_lines[1:] | join('\n') }}\n"