---
- name: Add Github host key
  become: yes
  become_user: jenkins
  lineinfile:
    dest: "{{ jenkins_user_home }}/.ssh/known_hosts"
    create: yes
    state: present
    line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
    regexp: "^github\\.com"

- name: Clone Git repo
  become: yes
  become_user: jenkins
  git:
    dest: "{{ repo_dir }}"
    repo: "{{ git_repo }}"
    force: yes
    version: "{{ branch }}"

- name: Copy Jenkins config files
  become: yes
  become_user: jenkins
  copy:
    src: files/
    dest: "{{ repo_dir }}/docker/jenkins/bootstrap"

- name: Process Jenkins templates
  become: yes
  become_user: jenkins
  shell: "{{ repo_dir }}/docker/jenkins/build.sh"

- name: Jenkins init config
  become: yes
  become_user: jenkins
  shell: "{{ repo_dir }}/docker/jenkins/init.sh"

---
- name: Add Github host key
  become: yes
  become_user: jenkins
  lineinfile:
    dest: "{{ jenkins_user_home }}/.ssh/known_hosts"
    create: yes
    state: present
    line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
    regexp: "^github\\.com"

- name: Configure Git
  become: yes
  become_user: jenkins
  git_config:
    name: "{{ item.name }}"
    scope: global
    value: "{{ item.value }}"
  with_items:
    - name: user.name
      value: Jenkins CI
    - name: user.email
      value: jenkins@unguiculus.io
    - name: alias.st
      value: status
    - name: alias.co
      value: checkout
    - name: alias.l
      value: log --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset"
    - name: alias.rhu
      value: reset --hard @{u}

- name: Clone Git repo
  become: yes
  become_user: jenkins
  git:
    dest: "{{ repo_dir }}"
    repo: "{{ git_repo }}"
    force: yes
    version: "{{ branch }}"

- name: Copy Jenkins config files
  become: yes
  become_user: jenkins
  copy:
    src: files/
    dest: "{{ repo_dir }}/docker/jenkins/bootstrap"

- name: Process Jenkins templates
  become: yes
  become_user: jenkins
  shell: "{{ repo_dir }}/docker/jenkins/build.sh"

- name: Jenkins init config
  become: yes
  become_user: jenkins
  shell: "{{ repo_dir }}/docker/jenkins/init.sh"

Add Git configuration for jenkins user
Add Git configuration for jenkins user
