mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-24 21:14:00 -07:00 
			
		
		
		
	Merge pull request #1404 from dagwieers/doc-fix1
Clarify how only_if works, also combined with with_items
This commit is contained in:
		
				commit
				
					
						5020af0a45
					
				
			
		
					 1 changed files with 12 additions and 4 deletions
				
			
		|  | @ -272,12 +272,20 @@ In Ansible 0.8, a few shortcuts are available for testing whether a variable is | |||
| 
 | ||||
|     tasks: | ||||
|         - action: command echo hi | ||||
|           only_if: is_set($some_variable) | ||||
|           only_if: is_set('$some_variable') | ||||
| 
 | ||||
| There is a matching 'is_unset' that works the same way.  Do not quote the variables inside the function. | ||||
| There is a matching 'is_unset' that works the same way.  Quoting the variable inside the function is mandatory. | ||||
| 
 | ||||
| While only_if is a pretty good option for advanced users, it exposes more guts of the engine than we'd like, and | ||||
| we can do better.  In 0.9, we will be adding 'when', which will be like a syntactic sugar for only_if and hide | ||||
| When combining `only_if` with `with_items`, be aware that the `only_if` statement is processed for each item. | ||||
| This is a deliberate design:: | ||||
| 
 | ||||
|     tasks: | ||||
|         - action: command echo $item | ||||
|           with_item: [ 0, 2, 4, 6, 8, 10 ] | ||||
|           only_if: "$item > 5" | ||||
| 
 | ||||
| While `only_if` is a pretty good option for advanced users, it exposes more guts of the engine than we'd like, and | ||||
| we can do better.  In 0.9, we will be adding `when`, which will be like a syntactic sugar for `only_if` and hide | ||||
| this level of complexity -- it will numerous built in operators. | ||||
| 
 | ||||
| Conditional Imports | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue