GithubHelp home page GithubHelp logo

tivrobo / ansible-win_git Goto Github PK

View Code? Open in Web Editor NEW
17.0 6.0 28.0 36 KB

win_git: Git Ansible module for Windows

License: GNU General Public License v3.0

PowerShell 84.63% Python 15.37%
git-ansible win-git ansible-modules ansible-windows

ansible-win_git's Introduction

ansible-win_git

Git module for Windows

Installation:

Copy win_git.ps1 and win_git.py files to default-module-path directory

Usage:

- name: git clone cool-thing
  win_git:
    repo: "[email protected]:tivrobo/Ansible-win_git.git"
    dest: "{{ ansible_env.TEMP }}\\Ansible-win_git"
    branch: master
    update: no
    recursive: yes
    replace_dest: no
    accept_hostkey: yes

Output:

ok: [windows2008r2.example.com] => {
  "changed": false, 
  "invocation": {
      "module_name": "win_git"
  }, 
  "win_git": {
    "accept_hostkey": true, 
    "changed": true, 
    "dest": "C:\\Users\\tivrobo\\AppData\\Local\\Temp\\Ansible-win_git", 
    "msg": "Successfully cloned [email protected]:tivrobo/Ansible-win_git.git into C:\\Users\\tivrobo\\AppData\\Local\\Temp\\Ansible-win_git.", 
    "repo": "[email protected]:tivrobo/Ansible-win_git.git",
    "output": "", 
    "recursive": true, 
    "replace_dest": false, 
    "return_code": 0
  }
}

TODO:

  • handle correct status change when using update
  • add check/diff mode support
  • check for idempotence
  • add tests

More info:

ansible-win_git's People

Contributors

michael-hay avatar pablodav avatar tivrobo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ansible-win_git's Issues

Unsure how to implement the win_git module

I have added win_git,ps1 and win_git.py to a library folder which is on the same level as my playbooks folder.

I am receiving a syntax error when I try to use the win_git module though. I think this is becuase ansible doesn't recognise the module. Do I need to reference the library folder somehow? Also will this work when both machines are windows?

You cannot call a method on a null-valued expression

I am running

[user@server dir]$ ansible --version ansible 2.5.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/rserve_user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

I have your module in my playbook library and am trying to create a very simple playbook using win_git

`---

This playbook uses the win_ping module to test connectivity to Windows hosts

  • name: Clone
    hosts: clients

    tasks:

    • name: Git Clone Repo
      win_git:
      name: "ssh://git@stash:port/foo/repoName.git"
      dest: "C:\temp"
      replace_dest: yes
      accept_hostkey: yes
      update: yes
      branch: master
      `

I get an error back from powershell complaining about a null value

`PLAY [Clone] *********************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************
ok: [server]

TASK [Git Clone Repo] ****************************************************************
fatal: [server]: FAILED! => {"changed": false, "msg": "Error cloning ssh://git@stash:port/foo/repoName.git to C:\temp! Msg: You cannot call a method on a null-valued expression. - ", "win_git": {"accept_hostkey": true, "branch": "master", "dest": "C:\temp", "git_opts": "--no-pager pull origin master", "method": "pull", "name": "ssh://git@stash:port/foo/repoName.git", "replace_dest": true, "update": true, "valid_url": "ssh://git@stash:port/foo/repoName.git is valid url"}}
to retry, use: --limit @/home/user/repo/clone.retry

PLAY RECAP ***********************************************************************************************************
server : ok=1 changed=0 unreachable=0 failed=1
`

I tried using different options but still no dice.

If I comment out the checkout function from the clone and update I no longer get an error but I still get no repo cloned. Any ideas?

Need help with win_git installation

Dear guys,

I'm running awx via docker container. How can I add this module into awx?
P/s: Tried to add win_git.ps1 and win_git.py into /usr/share/ansible/plugins/modules

Thank and regards,

powershell generates the wrong known_hosts file encoding

When using the Out-File Cmdlet the file encoding is wrong for SSH. SSH would only accept utf8, but by default the Cmdlet spits out utf16. The encoding option doesn't work as expected either. -Encoding utf8 writes with UTF8 with BOM, which doesn't work. The only way I found to make it work was with the ascii encoding. I don't know whether this will create problems in the long run, though.

git causes NativeCommandError

I am using Ansible 2.8.1 with latest win_git module targeting a Windows 10 Pro 1903 machine running Git for Windows 2.16.2. Updating an existing git clone fails, see below. Initial cloning fails with a similar issue.

TASK [win_git] ************************************************************************************
task path: ansible-win_git.yaml:10
Using module file library/win_git.ps1
Pipelining is enabled.
<192.168.xx.xx> ESTABLISH WINRM CONNECTION FOR USER: user on PORT 5986 TO 192.168.xx.xx
EXEC (via pipeline wrapper)
fatal: [win10pro]: FAILED! => {
    "changed": false,
    "cmd_msg": null,
    "msg": "Error cloning https://github.com/tivrobo/ansible-win_git.git to C:\\ansible-win_git! Msg: Already on 'master' - ",
    "win_git": {
        "accept_hostkey": true,
        "branch": "master",
        "clone": false,
        "dest": "C:\\ansible-win_git",
        "git_opts": "--no-pager pull origin master",
        "method": "pull",
        "recursive": true,
        "replace_dest": false,
        "repo": "https://github.com/tivrobo/ansible-win_git.git",
        "update": true,
        "valid_url": "https://github.com/tivrobo/ansible-win_git.git is valid url"
    }
}

I recognized that this is caused by git generating a NativeCommandError exception when being executing in Powershell:

PS C:\ansible-win_git> git --no-pager checkout master
Your branch is up to date with 'origin/master'.
git : Already on 'master'
At line:1 char:1
+ git --no-pager checkout master
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Already on 'master':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

As a work around I added the following into win_git.ps1:

$env:GIT_REDIRECT_STDERR = '2>&1'

This changes the behavior of git in Powershell to the following:

PS C:\ansible-win_git> $env:GIT_REDIRECT_STDERR = '2>&1'
PS C:\ansible-win_git> git --no-pager checkout master
Your branch is up to date with 'origin/master'.
Already on 'master'

No exception is thrown anymore. The drawback is all stderr is merged into stdout.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.