mirror of
				https://github.com/Rudd-O/ansible-qubes.git
				synced 2025-11-04 13:38:55 +01:00 
			
		
		
		
	JQ plugin added for lookups.
This commit is contained in:
		
							parent
							
								
									8873494af8
								
							
						
					
					
						commit
						03fc7da7de
					
				
							
								
								
									
										30
									
								
								lookup_plugins/jq.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								lookup_plugins/jq.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					from ansible.errors import AnsibleError
 | 
				
			||||||
 | 
					from ansible.plugins.lookup import LookupBase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
					    from __main__ import display
 | 
				
			||||||
 | 
					except ImportError:
 | 
				
			||||||
 | 
					    from ansible.utils.display import Display
 | 
				
			||||||
 | 
					    display = Display()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					UNDEFINED = object()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class LookupModule(LookupBase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def run(self, args, variables):
 | 
				
			||||||
 | 
					        i = json.dumps(args[0])
 | 
				
			||||||
 | 
					        c = ["jq", args[1]]
 | 
				
			||||||
 | 
					        p = subprocess.Popen(c, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
 | 
				
			||||||
 | 
					        o, e = p.communicate(i)
 | 
				
			||||||
 | 
					        r = p.wait()
 | 
				
			||||||
 | 
					        if r != 0 or e:
 | 
				
			||||||
 | 
					            assert 0, e
 | 
				
			||||||
 | 
					            raise subprocess.CalledProcessError(r, c, o, e)
 | 
				
			||||||
 | 
					        r = json.loads(o)
 | 
				
			||||||
 | 
					        return r
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user