0

As part of my Molecule test, I want to revert a previously created pyenv installation to an old state. The goal is to simulate a new Python version being released but not being available to pyenv because it hasn't been updated yet with git pull.

The relevant sections of my prepare.yml look like this:

- name: run Python role to install venv
  import_role:
    name: company.python

- name: unshallow pyenv repo
  command: cd /home/johndoe/.pyenv && git pull --unshallow

# Python 3.8.12 was released on Aug. 30, 2021 (see https://www.python.org/downloads/)
# Use pyenv commit from Aug. 23, 2021
- name: switch to old pyenv commit
  command: cd /home/johndoe/.pyenv && git checkout e9c8dfc197744cace4832d7ed3bfdd644445ff50

Unfortunately, ~johndoe/.pyenv still points to HEAD in master after the prepare step, and the repository is not unshallowed. Running these commands manually works. What am I missing?

The Molecule invocation does not report any errors either:

TASK [company.python : Print fact python_venv_paths] *************************
ok: [instance] => {
    "msg": [
        "/home/johndoe/.pyenv/versions/ansible-dependencies"
    ]
}

TASK [unshallow pyenv repo] ****************************************************
changed: [instance]

TASK [switch to old pyenv commit] **********************************************
changed: [instance]
oschlueter
  • 2,596
  • 1
  • 23
  • 46
  • I dont know anything about ansible but there is a git command `git show` that displays the latest commit. There also is the `git rev-parse ` to get the commit id, you could run that for both the remote branch (after fetching) and the local branch. Another option could be utilizing `git diff `. But in any case, you have to fetch first to be able to know what the remote looks like. – Torge Rosendahl Oct 13 '22 at 16:27
  • 3
    It looks like you're trying to execute a shell script with the `command` module; that won't work. I would expect that `switch to old pyenv commit` task to result in an error. Replacing `command` with `shell` might solve the problem, but so would replacing the `cd` command with the [`chdir` argument](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html#parameter-chdir) to the `command` task. Alternately, there is a [`git` module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html) that can probably do what you want. – larsks Oct 13 '22 at 16:52

0 Answers0