Hi guys,
Someone could help me ?
I cannot understand how to pass an ansible variable to powershell cmdlet via win_shell command .
Below my code :
tasks:
- set_fact:
target_ip: “lookup(‘dig’, inventory_hostname)” - win_shell: |
“Get-DHCPServerV4Lease -IPAddress "{{ target_ip }}"| Add-DhcpServerv4Reservation”
This return me also this one below :
changed: [host1] => {“changed”: true, “cmd”: “"Get-DHCPServerV4Lease -IPAddress \"lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"”, “delta”: “0:00:00.546871”, “end”: “2019-06-20 04:18:36.787461”, “rc”: 0, “start”: “2019-06-20 04:18:36.240590”, “stderr”: “At line:1 char:101\r\n+ … e -IPAddress \"lookup(‘dig’, inventory_hostname)\"| \r\nAdd-DhcpServerv4Reservation"\r\n+ ~~~~~~\r\nUnexpected token ‘lookup’ in expression or statement.\r\nAt line:1 char:114\r\n+ … \"lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"\r\n+ ~\r\nMissing expression after ‘,’.\r\nAt line:1 char:115\r\n+ … "lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"\r\n+ ~~~~~~~~~~~~~~~~~~\r\nUnexpected token ‘inventory_hostname’ in expression or statement.\r\nAt line:1 char:114\r\n+ … \"lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"\r\n+ ~\r\nMissing closing ‘)’ in expression.\r\nAt line:1 char:133\r\n+ … entory_hostname)\"| Add-DhcpServerv4Reservation"\r\n+ ~\r\nUnexpected token ‘)’ in expression or statement.\r\n + CategoryInfo : ParserError: ( , ParentContainsErrorRecordEx \r\n ception\r\n + FullyQualifiedErrorId : UnexpectedToken”, “stderr_lines”: [“At line:1 char:101”, "+ … e -IPAddress \"lookup(‘dig’, inventory_hostname)\"| “, “Add-DhcpServerv4Reservation"”, “+ ~~~~~~”, “Unexpected token ‘lookup’ in expression or statement.”, “At line:1 char:114”, “+ … \"lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"”, “+ ~”, “Missing expression after ‘,’.”, “At line:1 char:115”, “+ … "lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"”, “+ ~~~~~~~~~~~~~~~~~~”, “Unexpected token ‘inventory_hostname’ in expression or statement.”, “At line:1 char:114”, “+ … \"lookup(‘dig’, inventory_hostname)\"| Add-DhcpServerv4Reservation"”, “+ ~”, “Missing closing ‘)’ in expression.”, “At line:1 char:133”, “+ … entory_hostname)\"| Add-DhcpServerv4Reservation"”, “+ ~”, “Unexpected token ‘)’ in expression or statement.”, " + CategoryInfo : ParserError: ( , ParentContainsErrorRecordEx “, " ception”, " + FullyQualifiedErrorId : UnexpectedToken”], “stdout”: “”, “stdout_lines”: }
I