Ansible via Ansible Pull can't find file in `template: validate="stat %s"`

758 Views Asked by At

When using Ansible through Ansible Pull, the template directive's validate step fails to find the file specified by %s.

"No such file" error reported by ansible-pull:

TASK [ssh : place ssh config file] *********************************************
fatal: [localhost]: FAILED! => {
    "changed": true,
    "cmd": "sshd -t -f /home/nhooey/.ansible/tmp/ansible-tmp-1453485441.94-279324955743/source",
    "failed": true,
    "msg": "[Errno 2] No such file or directory",
    "rc": 2
}

Problematic template directive:

- name: place ssh config file
  template:
    src: etc/ssh/sshd_config
    dest: /etc/ssh/sshd_config
    owner: root
    group: root
    mode: 0644
    validate: 'sshd -t -f %s'

This happens with either Ansible 1.9.4 or 2.0.0.2 from (Python 2.7's Pip) and only when using Ansible Pull. Running ansible-playbook locally after manually checking out the repository works fine.

Unfortunately I'm not able to reproduce this error in the trivial case with a sample repository that I created.

Failure to reproduce error with simple test case:

$ virtualenv .venv && source .venv/bin/activate && pip install ansible
$ ansible-pull --directory /tmp/ansible-test \
    --url https://github.com/nhooey/ansible-pull-template-validate-bug.git playbook.yaml
Starting Ansible Pull at 2016-01-22 13:14:51
/Users/nhooey/git/github/nhooey/ansible-pull-template-validate-bug/.venv/bin/ansible-pull \
  --directory /tmp/ansible-test \
  --url https://github.com/nhooey/ansible-pull-template-validate-bug.git \
  playbook.yaml
localhost | SUCCESS => {
    "after": "07bb13992910e0efe30d071d5f5a2a2e88251045",
    "before": "07bb13992910e0efe30d071d5f5a2a2e88251045",
    "changed": false
}
 [WARNING]: provided hosts list is empty, only localhost is available

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [Delete template file] ****************************************************
changed: [localhost]

TASK [Test template validation] ************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0

Playbook that won't fail in the simple test case above:

---

- hosts: localhost

  tasks:
    - name: Delete template file
      file:
        path: /tmp/file
        state: absent

    - name: Test template validation
      template:
        src: file
        dest: /tmp/file
        validate: 'ls %s'

It seems like there could be a problem with the timing around when ansible-pull creates and deletes temporary files in Ansible.

What's happening?

1

There are 1 best solutions below

0
On

It's saying that it can't find sshd because it's not in the path. Silly me...