
This is preparation for a later version of ansbile-lint, which finds missing names on blocks. This seems a reasonable rule, and the Ansible manual says [1] Names for blocks have been available since Ansible 2.3. We recommend using names in all tasks, within blocks or elsewhere, for better visibility into the tasks being executed when you run the playbook. This simply adds a name tag for blocks that are missing it. This should have no operational change, but allows us to update the linter in a follow-on change. [1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html Change-Id: I92ed4616775650aced352bc9088a07e919f1a25f
73 lines
2.3 KiB
YAML
73 lines
2.3 KiB
YAML
- name: Upload git mirror
|
|
block:
|
|
- name: Create SSH private key tempfile
|
|
tempfile:
|
|
state: file
|
|
register: ssh_private_key_tmp
|
|
|
|
- name: Set up private key
|
|
copy:
|
|
content: "{{ git_mirror_credentials.ssh_key }}"
|
|
dest: "{{ ssh_private_key_tmp.path }}"
|
|
mode: 0600
|
|
|
|
# If the markers in an id_rsa don't end with a newline some
|
|
# versions of ssh won't read the key.
|
|
- name: Ensure ssh_key ends with newline
|
|
shell: |
|
|
echo >> {{ ssh_private_key_tmp.path }}
|
|
|
|
- name: Generate SSH configuration
|
|
set_fact:
|
|
ssh_config: |
|
|
host {{ git_mirror_credentials.host }}
|
|
HostName {{ git_mirror_credentials.host }}
|
|
IdentityFile {{ ssh_private_key_tmp.path }}
|
|
User {{ git_mirror_credentials.user }}
|
|
|
|
- name: Write SSH configuration to ~/.ssh/config
|
|
blockinfile:
|
|
state: present
|
|
path: "{{ ansible_user_dir }}/.ssh/config"
|
|
create: yes
|
|
mode: 0600
|
|
block: "{{ ssh_config }}"
|
|
|
|
- name: Add host key to known hosts
|
|
known_hosts:
|
|
state: present
|
|
name: "{{ git_mirror_credentials.host }}"
|
|
key: "{{ git_mirror_credentials.host_key }}"
|
|
|
|
- name: Mirror the git repository
|
|
command: git push --mirror {{ git_mirror_credentials.user }}@{{ git_mirror_credentials.host }}:{{ git_mirror_repository }}
|
|
args:
|
|
chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
|
|
tags:
|
|
- skip_ansible_lint
|
|
register: result
|
|
retries: 3
|
|
delay: 5
|
|
until: result is not failed
|
|
|
|
always:
|
|
# Registered variables below are only used for integration testing
|
|
- name: Remove SSH private key from disk
|
|
command: "shred --remove {{ ssh_private_key_tmp.path }}"
|
|
register: git_mirror_key_removed
|
|
|
|
- name: Remove SSH configuration in ~/.ssh/config
|
|
blockinfile:
|
|
state: absent
|
|
path: "{{ ansible_user_dir }}/.ssh/config"
|
|
mode: 0600
|
|
block: "{{ ssh_config }}"
|
|
register: git_mirror_ssh_config_removed
|
|
|
|
- name: Remove host key from known hosts
|
|
known_hosts:
|
|
state: absent
|
|
name: "{{ git_mirror_credentials.host }}"
|
|
key: "{{ git_mirror_credentials.host_key }}"
|
|
register: git_mirror_host_key_removed
|