1

I have an Ansible project that involves the following task:

- name: Perform a git init in source folder
  ansible.builtin.command:
    cmd: git init
    chdir: ~/Projects/kernel/src
    creates: ~/kernel/src/.git

However ansible-lint does not like this:

WARNING  Listing 1 violation(s) that are fatal
command-instead-of-module: git used in place of git module (warning)

I have tried using the ansible.builtin.git module but I can't seem to find a way to make it just do an init.

Any suggestions?

Stephen

I was trying to write an Ansible task that essentially performs a git init in a folder without ansible-lint complaining. But I can't seen to find an ansible-lint clean way of doing this.

torek
  • 448,244
  • 59
  • 642
  • 775
  • the ansible-lint message is informing that instead of using the Ansible module, command is used; in this case, the error message is correct as that is the case. What was the error message when the git module was used? – Carlos Monroy Nieblas Oct 28 '22 at 21:50
  • Does this answer your question? [Ansible: how to init git bare repository and clone it to the same machine?](https://stackoverflow.com/questions/39204455/ansible-how-to-init-git-bare-repository-and-clone-it-to-the-same-machine) – Carlos Monroy Nieblas Oct 28 '22 at 21:52

2 Answers2

2

You can skip false positives from ansible-lint, using skipping rules

- name: Perform a git init in source folder
  ansible.builtin.command:
    cmd: git init # noqa command-instead-of-module
    chdir: ~/Projects/kernel/src
    creates: ~/kernel/src/.git
HiroCereal
  • 550
  • 1
  • 11
  • Thanks @HiroCereal. I have that skip in my ansible-lint config but I consider that a work-around and not a proper fix. – sbates-nvme Oct 29 '22 at 15:02
1

Ansible’s git module requires repository as mandatory parameter, create a remote repository before initialising the local repo.

Task with ansible’s built in git would look like

- name: Perform git init
  git: 
    repo: https://github.com/username/repo.git
    dest: /home/user/Projects/kernel/repo.git
    bare: yes
    update: no

Also prefer absolute path over relative.

franklinsijo
  • 17,784
  • 4
  • 45
  • 63
  • Thanks @franklinsijo. Unforuntely this generates a new ansible-lint error as follows: ```latest[git]: Result of the command may vary on subsequent runs. ~/Projects/batesste-ansible/roles/kernel_setup/tasks/main.yml:46 Task/Handler: Perform a git init in source folder ``` – sbates-nvme Oct 29 '22 at 15:11