Ansible-pull systemd unit fails

I now have the very weird problem ansible-pull works perfectly fine as user ansible, but when doing the same from a systemd service fails without any useful logs apart from this:

systemd[1]: ansible-pull.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
systemd[1]: ansible-pull.service: Failed with result 'exit-code'.

The unit file looks like this:

[Unit]
Description=Manage server configuration with ansible-pull
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/ansible-pull -U https://example.com/ansible.git --clean --diff initiate.yml
User=ansible

[Install]
WantedBy=multi-user.target

Anyone have a clue what might be wrong, or how I could get more detailed logs or error messages?

Wouldn’t you need to specify where to pull it too?

  $ ansible-pull --help | grep DEST
                [--purge] [-o] [-s SLEEP] [-f] [-d DEST] [-U URL] [--full]
  -d, --directory DEST  path to the directory to which Ansible will checkout

If not specified, it will pull into ~/.ansible/pull/HOSTNAME, but even when the command is simply ansible-pull --version it fails similarly.

There are more details in the system journal. For example, running journalctl -b -u ansible-pull --no-hostname -o short --no-pager after having attempted to start your service from your initial post on my system produces:

$ sudo journalctl -b -u ansible-pull --no-hostname -o short --no-pager
Jan 06 07:10:50 systemd[1]: Starting ansible-pull.service - Manage server configuration with ansible-pull...
Jan 06 07:10:51 python3[37407]: ansible-git Invoked with name=https://example.com/ansible.git dest=/home/ansible/.ansible/pull/foxtrot depth=1 force=True repo=https://example.com/ansible.git version=HEAD remote=origin clone=True update=True verify_commit=False gpg_whitelist=[] accept_hostkey=False accept_newhostkey=False bare=False recursive=True single_branch=False track_submodules=False refspec=None reference=None key_file=None ssh_opts=None executable=None umask=None archive=None archive_prefix=None separate_git_dir=None
Jan 06 07:10:53 ansible-pull[37389]: [WARNING]: Could not match supplied host pattern, ignoring: foxtrot
Jan 06 07:10:53 ansible-pull[37389]: localhost | FAILED! => {
Jan 06 07:10:53 ansible-pull[37389]:     "changed": false,
Jan 06 07:10:53 ansible-pull[37389]:     "cmd": "/usr/bin/git ls-remote https://example.com/ansible.git -h refs/heads/HEAD",
Jan 06 07:10:53 ansible-pull[37389]:     "msg": "fatal: repository 'https://example.com/ansible.git/' not found",
Jan 06 07:10:53 ansible-pull[37389]:     "rc": 128,
Jan 06 07:10:53 ansible-pull[37389]:     "stderr": "fatal: repository 'https://example.com/ansible.git/' not found\n",
Jan 06 07:10:53 ansible-pull[37389]:     "stderr_lines": [
Jan 06 07:10:53 ansible-pull[37389]:         "fatal: repository 'https://example.com/ansible.git/' not found"
Jan 06 07:10:53 ansible-pull[37389]:     ],
Jan 06 07:10:53 ansible-pull[37389]:     "stdout": "",
Jan 06 07:10:53 ansible-pull[37389]:     "stdout_lines": []
Jan 06 07:10:53 ansible-pull[37389]: }
Jan 06 07:10:53 ansible-pull[37389]: Starting Ansible Pull at 2025-01-06 07:10:51
Jan 06 07:10:53 ansible-pull[37389]: /usr/bin/ansible-pull -U https://example.com/ansible.git --clean --diff initiate.yml
Jan 06 07:10:53 systemd[1]: ansible-pull.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jan 06 07:10:53 systemd[1]: ansible-pull.service: Failed with result 'exit-code'.
Jan 06 07:10:53 systemd[1]: Failed to start ansible-pull.service - Manage server configuration with ansible-pull.
Jan 06 07:10:53 systemd[1]: ansible-pull.service: Consumed 873ms CPU time, 139.3M memory peak.

Obviously mine failed because I didn’t point at a valid https repo, but the point is there’s more information in the system journal than is reported by systemctl status ansible-pull.service.

2 Likes

Thanks, I have no idea what was changed, but just tried again and now it works…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.