 - name: template access credentials into .rc file
   template:
     src: credentials.rc
     dest: /home/{{ admin_user }}/.credentialsrc

 - name: source credentals in bashrc
   lineinfile:
     dest: "/home/{{ admin_user }}/.bashrc"
     line: source ~/.credentialsrc

 - name: extract generated public key from bastion
   shell: cat /home/{{ admin_user }}/.ssh/id_rsa.pub
   register: bastion_pub_key

 - name: add ssh key name to credentials
   lineinfile:
     dest: "/home/{{ admin_user }}/.credentialsrc"
     line: "export DO_SSH_KEY_NAME={{ admin_user }}.bastion"

 - name: deploy bastion public key to DO
   digital_ocean:
     state: present
     command: ssh
     name: "{{ admin_user }}.bastion"
     client_id: "{{ creds.DIGITALOCEAN_CLIENT_ID }}"
     api_key: "{{ creds.DIGITALOCEAN_API_KEY }}"
     ssh_pub_key: "{{ bastion_pub_key.stdout }}"

 - name: template access credentials into .rc file
   template:
     src: credentials.rc
     dest: /home/{{ admin_user }}/.credentialsrc

 - name: source credentals in bashrc
   lineinfile:
     dest: "/home/{{ admin_user }}/.bashrc"
     line: source ~/.credentialsrc

 - name: extract generated public key from bastion
   shell: cat /home/{{ admin_user }}/.ssh/id_rsa.pub
   register: bastion_pub_key

 - name: add ssh key name to credentials
   lineinfile:
     dest: "/home/{{ admin_user }}/.credentialsrc"
     line: "export DO_SSH_KEY_NAME={{ admin_user }}.bastion"

 - name: wipe out old bastion public key on DO
   digital_ocean:
     state: absent
     command: ssh
     name: "{{ admin_user }}.bastion"
     client_id: "{{ creds.DIGITALOCEAN_CLIENT_ID }}"
     api_key: "{{ creds.DIGITALOCEAN_API_KEY }}"

 - name: deploy bastion public key to DO
   digital_ocean:
     state: present
     command: ssh
     name: "{{ admin_user }}.bastion"
     client_id: "{{ creds.DIGITALOCEAN_CLIENT_ID }}"
     api_key: "{{ creds.DIGITALOCEAN_API_KEY }}"
     ssh_pub_key: "{{ bastion_pub_key.stdout }}"

Replace bastion key on DO when provisioning new bastion
Replace bastion key on DO when provisioning new bastion
