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

ansible-pull does not recognize git updated branches #604

Closed
go2sh opened this issue Jul 17, 2012 · 14 comments
Closed

ansible-pull does not recognize git updated branches #604

go2sh opened this issue Jul 17, 2012 · 14 comments

Comments

@go2sh
Copy link
Contributor

go2sh commented Jul 17, 2012

I'm using ansible-pull as cron.daily job for syncing new packages to my clients.
But right now it fails to pull updates from the remote host.
I run ansible-pull like this:

#!/bin/bash
# Cron job to git clone/pull a repo and then run locally
echo "127.0.0.1" > /tmp/ansible_hosts
su root -c 'env ANSIBLE_HOSTS="/tmp/ansible_hosts" ansible-pull -d /var/lib/ansible/local -U ansible-git:ansible -C ansible-update >/var/log/ansible-pull.log 2>&1'

ansible-git is defind in my ssh_config. The Output from ansible-pull is:

127.0.0.1 | success >> {
    "after": "971fe17", 
    "before": "971fe17", 
    "changed": false
}

But git status shows:

~# git status
# On branch ansible-update
# Your branch is behind 'origin/ansible-update' by 3 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)
@ghost ghost assigned sfromm Jul 17, 2012
@mpdehaan
Copy link
Contributor

Assigning to sfromm, though if you'd like to help figure it out that would be welcome.

@go2sh
Copy link
Contributor Author

go2sh commented Jul 17, 2012

I will try to debug the code. But my python skills are very poor.

@mpdehaan
Copy link
Contributor

was this repo originally copied instead of cloned? Currently the git module expects a repo that was cloned with the "git clone" command.

@mpdehaan
Copy link
Contributor

see #601

@goozbach
Copy link
Contributor

Could be related to #601

@sfromm
Copy link
Contributor

sfromm commented Jul 17, 2012

Not necessarily related to this issue, but -U means --url with ansible-pull. Not --sudo-user as it does with ansible-playbook.

@mpdehaan
Copy link
Contributor

closing as duplicate of #601 since I haven't heard anything, let me know if you disagree at this repo was originated in some way other than a git clone (in which case it's not a dup)

@go2sh
Copy link
Contributor Author

go2sh commented Jul 18, 2012

It was cloned by ansible-pull script, because the local dir was empty before the first run.

@mpdehaan mpdehaan reopened this Jul 18, 2012
@mpdehaan
Copy link
Contributor

ok, reopening, git module has additional things to fix probably

@sfromm
Copy link
Contributor

sfromm commented Jul 18, 2012

@go2sh, please provide the output of git branch -a. Thanks.

@sfromm
Copy link
Contributor

sfromm commented Jul 18, 2012

@go2sh: One more question: what version of ansible are you using?

@sfromm
Copy link
Contributor

sfromm commented Jul 18, 2012

I can replicate the problem by if I update the local repository with git (git pull) and then try to update it with ansible's git module. The latter step fails.

It appears the git module is basically doing the following:

git checkout master
git pull -u origin
git checkout <branchname> --force

The first step, git checkout master, is called by switchLocalBranch() from inside pull(), line 154 in my ansible repo. My repo is at 13abe50, a little bit behind. If the module doesn't check out master, the pull step will work as expected and the repo will go to HEAD for the desired branch.

One other thing I would add: when creating the local branch at line 151 (git checkout -b %s origin/%s), I think it should also use the option --track since it is meant to track the upstream branch.

@go2sh
Copy link
Contributor Author

go2sh commented Jul 18, 2012

/var/lib/ansible/local# git branch -a
* ansible-update
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/ansible-update
  remotes/origin/master

I use ansible 0.6 .

@sfromm
Copy link
Contributor

sfromm commented Jul 20, 2012

The git module probably needs some deeper work, but I opted to fix this specific issue instead. I'd appreciate comments on skipping the step switchLocalBranch( branch ) in pull().

mpdehaan pushed a commit that referenced this issue Jul 26, 2012
This drops the branch option.  The version option is overloaded
to mean either a sha1, branch, or tag.  This also adds the option
'remote' which defaults to 'origin'.
clone() was simplified by removing the checkout operation.  That
happens later when switch_version() is called.

Added the methods get_branches(), is_remote_branch(), and
is_local_branch().  get_branches() returns an array listing all
of the branches for the git repository.  is_remote_branch() checks
whether the arguments supplied correspond to a remote branch.
Similarly, is_local_branch() checks for a local branch.

The pull() method now checks to see if it is on the desired branch.
If not, it checks out the requested branch and then does a pull.
This should keep issue #604 still fixed.

switch_version(), formerly switchver(), looks to see if it is
checking out a branch.  If a branch, it checks it out with the --track
option.  This type of checkout was in pull() before.

Updated pull, clone, and switch_version to return (rc, out, err).
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants