Redho Ayassa Redho Ayassa - 2 months ago 11
Git Question

How to retrieve the commit message of the checked out code with Ansible?

I have created an Ansible Playbook for checking out code from Git repository.

How do I retrieve the latest commit message of the checked out code with Ansible?

Answer

You can use git log to get the last commit message and save them in a variable. Something like this:

- name: get latest commit message
  shell: "git log --pretty="%s" -n1"
  args:
    chdir: "{{ path }}"
  register: latest_commit_message

Then you get the latest commit and save them in the variable latest_commit_message.

With --pretty you can define the output format you need.