1

I am new to ansible and trying to write a basic playbook for mongodb backup with simplest method. here is what i am trying to do:

---
- hosts: mongo
  tasks:
  - name: Mongo Dump
    command: mongodump --out mdb_backup/mongodb_backup/
  - name: MongoDb Backup 
    command: "{{item}} chdir=~/mdb_backup/mongodb_backup/"
    with_items:
     - pwd
     - git add
     - git commit -m "Updates"
     - git push origin master

And my error is:

"warnings": ["Consider using git module rather than running git"]} [WARNING]: Consider using git module rather than running git

I have idea about ansible git module but I don't know how to use it in my scenario. IS there anyone can help?

Ali Warrich
  • 21
  • 1
  • 2

1 Answers1

4

This only is a warning, your code should still work.

The warnings are annoying sometimes because Ansible only checks for some simple strings and it's not very rare that the mentioned Ansible modules (git in this case) lack the features required to do so. And that also is the case here. The git module can only clone/checkout repositories but it can not add files, commit or push. So you're not doing anything wrong there.

To get rid of warning you could simply do this:

with_items:
  - pwd
  - `which git` add
  - `which git` commit -m "Updates"
  - `which git` push origin master

Now Ansible sees which and not git as the command.

udondan
  • 2,001
  • 14
  • 18
  • I tried to do this syntax error is coming: {The offending line appears to be: - pwd - `which git` add ^ here} – Ali Warrich Mar 02 '16 at 09:10
  • My indention might have been wrong. Can you try with one more whitespace? If that still does not work, try to quote the list elements. – udondan Mar 02 '16 at 09:30