Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Source Control module: git add/commit/push #68493

Closed
wants to merge 20 commits into from
Closed

NEW Source Control module: git add/commit/push #68493

wants to merge 20 commits into from

Conversation

lvrfrc87
Copy link
Contributor

SUMMARY

New module to add git add git commit and git push functionalities to Ansible.

This is particularly useful for example, network automation where Ansible is used in a CI/CD pipeline for template rendering and device provisioning. With this modules, all changes done in the repo during pipeline iteration (i.e. rendered template or test results) can be pushed back into the repo.

This module has been requested back in December 2018. See here: #50334

https and ssh git channels are both supported.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME
      git_acp:
        folder_path: /Users/federicoolivieri/git/git_test_module
        user: Federico87
        token: zECE5x88MtfWz8DofZYx
        comment: Add [ test.txt, tax.txt ]
        add: [ test.txt, tax.txt ]
        branch: master
        mode: https
        url: https://gitlab.com/networkAutomation/git_test_module.git
      git_acp:
        folder_path: /Users/federicoolivieri/git/git_test_module
        comment: Add .
        branch: master
        mode: ssh
        url: git@gitlab.com:networkAutomation/git_test_module.git

@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2020

The test ansible-test sanity --test validate-modules [explain] failed with 3 errors:

lib/ansible/modules/source_control/git_acp.py:0:0: mutually_exclusive-unknown: mutually_exclusive contains terms which are not part of argument_spec: https, ssh
lib/ansible/modules/source_control/git_acp.py:116:0: import-placement: Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/source_control/git_acp.py:118:0: import-placement: Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 ci_verified Changes made in this PR are causing tests to fail. has_issue module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. source_control Source-control category support:community This issue/PR relates to code supported by the Ansible community. labels Mar 26, 2020
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Mar 26, 2020
@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2020

@Lunik @SamyCoenen @adrianmoisey @andreparames @bincyber @catcombo @dj-wasabi @djmattyg007 @dsummersl @markuman @marwatk @mgedmin @pcgentry @stpierre @waheedi @yeukhon

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 26, 2020
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Mar 26, 2020
@ansibot
Copy link
Contributor

ansibot commented Mar 27, 2020

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

test/integration/targets/git_acp/tasks/https.yml:54:1: empty-lines: too many blank lines (1 > 0)

click here for bot help

@gundalow
Copy link
Contributor

Hi @FedericoOlivieri
Unfortunately, I missed you ni #ansible-devel
This repository ansible/ansible isn't accepting any more Pull request.

The source control modules are going in community.general

Could you please raise a new PR against https://github.com/ansible-collections/community.general/

It's amazing that you've added integration test, thank you.

If you look at the existing integration tests we have for the git module they create a local repository for testing. This should avoid the conflicts you are seeing, as well as the dependency on your your gitlab instance. https://github.com/ansible/ansible/blob/devel/test/integration/targets/git/tasks/setup-local-repos.yml

In a single PR could you please

  1. Create an new directory called plugins/modules/source_control/git/
  2. Tests go into tests/integration/targets
  3. Update tests to use local repos

@tadeboro
Copy link
Contributor

tadeboro commented Mar 27, 2020

@FedericoOlivieri Do note that if you want to test push/fetch/pull operations, you will almost certainly want to set up a bare repo. Git will complain if you try to push to the repo that has something check out.

General steps for creating and population a bare git repo would be:

git init --bare repo.git

git clone bare.git local_copy
cd local_copy
echo foo > foo.txt
git add foo.txt
git commit -m "Add foo"
git push

@lvrfrc87
Copy link
Contributor Author

@tadeboro @gundalow Thanks for your suggestion. I will raise a new PR against community.general. Regarding the integration test, your suggestions are indeed valuable and I will try to draft something based on that.

However, this module aim to commit and push changes in remote via SSH and HTTPs with user and token. Testing against a local repo won't let trigger all the commands required to push changes to a remote.

@lvrfrc87
Copy link
Contributor Author

@lvrfrc87 lvrfrc87 closed this Mar 27, 2020
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Mar 27, 2020
@ansible ansible locked and limited conversation to collaborators Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 has_issue module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_module This PR includes a new module. new_plugin This PR includes a new plugin. source_control Source-control category support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants