1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
Find a file
Dag Wieers 302eeae65d Do not register variable if host has been skipped
Executive summary: skipping a host corrupts a variable (when it is registered)

We have a play existing out of multiple tasks that check a condition, if one of these tasks fails we want to skip all next tasks in the playbook. I noticed that if we skip a task because a certain condition is met, and this task has a register-attribute, I loose the value in the variable. Which means we cannot use that variable in subsequent tasks to evaluate because it was skipped:

```
- action: command test -d /some/directory
  register: task

- action: command test -f /some/directory/file
  register: task
  only_if: '${task.rc} == 0'

- action: do something else
  only_if: '${task.rc} == 0'
```

In the above example, if the second task is skipped (because the first failed), the third action will end with a "SyntaxError: invalid syntax" complaining about the unsubstituted ${task.rc} (even though it was set by the first task and used for skipping the second).

The following play demonstrates the problem:

```
- name: Test register on ignored tasks
  hosts: all
  gather_facts: no

  vars:
    skip: true
    task: { 'rc': 666 }

  tasks:
  - action: debug msg='skip = ${skip}, task.rc = ${task.rc}'

  - name: Skip this task, just to test if task has changed
    action: command ls
    register: task
    only_if: '${skip} != True'

  - action: debug msg='skip = ${skip}, task.rc = ${task.rc}'

  - name: Now use task value
    action: command echo 'Works !'
    only_if: '${task.rc} == 0'
```

And the enclosed fix, fixes the above problem.
2012-11-13 16:57:10 +01:00
bin ansible-playbook verifies playbooks exist before running them 2012-11-11 18:08:35 -08:00
docs/man Manpage documentation ALSO should be sorted 2012-11-03 18:54:38 -04:00
docsite Added Action.IO to who_uses_ansible and ansible-provisioning to contribs 2012-11-09 17:52:54 +01:00
examples Merge pull request #1527 from fdavis/devel 2012-11-08 16:42:37 -08:00
hacking Add ability to specify syslog facility for modules 2012-11-11 00:14:08 -08:00
lib/ansible Do not register variable if host has been skipped 2012-11-13 16:57:10 +01:00
library Merge pull request #1590 from romeotheriault/minor-freebsd-user-module-fixes 2012-11-10 06:33:13 -08:00
packaging Add some python packages too 2012-11-08 20:28:32 +01:00
plugins While I haven't done this, it is possible to bring up an instance 2012-11-07 16:56:45 -08:00
test Add parameterized playbook includes 2012-11-09 15:43:49 +01:00
.gitignore Fix documentation consistency in .gitignore 2012-10-12 17:37:30 -04:00
CHANGELOG.md Added changelog note about 'when' 2012-11-11 11:59:38 -05:00
CONTRIBUTING.md Add a bit more info about tests to CONTRIBUTING 2012-10-21 07:15:30 -04:00
COPYING license file should be in source tree 2012-03-15 20:24:22 -04:00
Makefile moduleformatter.py should include our own ansible clone 2012-11-12 14:22:30 +01:00
MANIFEST.in Add some docs/examples 2012-08-14 13:05:44 -04:00
README.md Update website link 2012-09-24 21:56:37 -04:00
RELEASES.txt Adds release date for Cathedral 2012-10-20 17:21:10 -07:00
setup.py Add ansible.runner.filter_plugins package to setup.py 2012-11-05 15:23:04 +01:00
VERSION Release version bump for 0.9 (development branch) 2012-10-19 21:01:57 -04:00

Ansible

Ansible is a radically simple configuration-management, deployment, task-execution, and multinode orchestration framework.

Read the documentation and more at http://ansible.cc

Design Principles

  • Dead simple setup
  • Super fast & parallel by default
  • No server or client daemons; use existing SSHd
  • No additional software required on client boxes
  • Modules can be written in ANY language
  • Awesome API for creating very powerful distributed scripts
  • Be usable as non-root
  • The easiest config management system to use, ever.

Get Involved

Branch Info

  • Releases are named after Van Halen songs.
  • The devel branch corresponds to the release actively under development.
  • Various release-X.Y branches exist for previous releases
  • We'd love to have your contributions, read "CONTRIBUTING.md" for process notes.

Author

Michael DeHaan -- michael.dehaan@gmail.com

http://michaeldehaan.net