*Hi guys*.
*This is my code*:
---
- name: Multi-line shell
win_shell:
## Creating Scopes
Add-DhcpServerv4Scope -Name "{{ hebrew_site_name }}" -StartRange "{{
DHCP_computers_segment }}.61" -EndRange "{{ DHCP_computers_segment }}.243"
-SubnetMask "255.255.255.0" -LeaseDuration "8.00:00:00"
Add-DhcpServerv4Scope -Name "{{ hebrew_site_name }} טלפוניה" -StartRange "{{
DHCP_telephony_segment }}.61" -EndRange "{{ DHCP_telephony_segment }}.243"
-SubnetMask "255.255.255.0" -LeaseDuration "8.00:00:00"
*Error*:
2020-02-23 13:33:51,237 p=54513
u=ansible n=ansible | PLAY [--------------- Creating VLAN 2,5
IP pools on dhcp1 ---------------] ********************
2020-02-23 13:33:51,251 p=54513
u=ansible n=ansible | TASK [set_fact]
***********************************************************************************
2020-02-23 13:33:51,270 p=54513 u=ansible n=ansible | ok: [dhcp-test]
2020-02-23 13:33:51,275 p=54513
u=ansible n=ansible | TASK [include_vars]
*******************************************************************************
2020-02-23 13:33:51,293 p=54513 u=ansible n=ansible | ok: [dhcp-test]
2020-02-23 13:33:51,297 p=54513
u=ansible n=ansible | TASK [include_role : new_branch]
******************************************************************
2020-02-23 13:33:51,612 p=54513
u=ansible n=ansible | TASK [new_branch : Multi-line shell]
**************************************************************
2020-02-23 13:33:51,742 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | Starting new HTTPS connection (1
): dhcp-test
2020-02-23 13:33:51,767 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 401 0
2020-02-23 13:33:51,770 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool
| Resetting dropped connection: dhcp-test
2020-02-23 13:33:51,794 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 401 0
2020-02-23 13:33:51,872 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 1629
2020-02-23 13:33:51,884 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 847
2020-02-23 13:33:52,443 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 753
2020-02-23 13:33:53,177 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 998
2020-02-23 13:33:57,774 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 3575
2020-02-23 13:33:57,779 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 757
2020-02-23 13:33:57,784 p=54528 u=ansible n=
requests.packages.urllib3.connectionpool | "POST /wsman HTTP/1.1" 200 602
2020-02-23 13:33:57,789 p=54513
u=ansible n=ansible | fatal: [dhcp-test]: FAILED! => {"changed": true,
"cmd": "Add-DhcpServerv4Scope
-Name \"אור-יהודה-מומה\" -StartRange \"10.90.88.61\" -EndRange \
"10.90.88.243\" -SubnetMask \"255.255.255.0\" -LeaseDuration \"8.00:00:00\"
Add-DhcpServerv4Scope -Name \"אור-יהודה-מומה טלפוניה\" -StartRange \
"10.95.88.61\" -EndRange \"10.95.88.243\" -SubnetMask \"255.255.255.0\"
-LeaseDuration \"8.00:00:00\"", "delta": "0:00:03.656283", "end": "
2020-02-23 11:33:57.948151", "msg": "non-zero return code", "rc": 1,
"start": "2020-02-23 11:33:54.291867", "stderr"
: "Add-DhcpServerv4Scope : Cannot bind parameter because parameter 'Name'
is specified more than
once. To provide \r\nmultiple values to parameters that can accept multiple
values, use the array syntax. For example,
\"-parameter \r\nvalue1,value2,value3\".\r\nAt line:1 char:239\r\n+ ... 55.
0\" -LeaseDuration \"8.00:00:00\" Add-DhcpServerv4Scope
-Name \"אור-יה ...\r\n+
~~~~~\r\n + CategoryInfo :
InvalidArgument: (:) [Add-DhcpServerv4Scope], ParameterBindingException
\r\n + FullyQualifiedErrorId :
ParameterAlreadyBound,Add-DhcpServerv4Scope", "stderr_lines": ["
Add-DhcpServerv4Scope : Cannot bind parameter because parameter 'Name' is
specified more than once. To provide ", "
multiple values to parameters that can accept multiple values, use the array
syntax.
For example, \"-parameter ", "value1,value2,value3\".", "At line:1 char:239
", "+ ... 55.0\" -LeaseDuration \"8.00:00:00\"
Add-DhcpServerv4Scope -Name \"אור-יה ...",
"+ ~~~~~"
, " +
CategoryInfo : InvalidArgument: (:) [Add-DhcpServerv4Scope],
ParameterBindingException", " + FullyQualifiedErrorId :
ParameterAlreadyBound,Add-DhcpServerv4Scope"], "stdout": "", "
stdout_lines": []}
2020-02-23 13:33:57,791 p=54513
u=ansible n=ansible | PLAY RECAP
****************************************************************************************
2020-02-23 13:33:57,791 p=54513
u=ansible n=ansible | dhcp-test : ok=2 changed=0
unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
*If i'm commenting any one of the add-scope commands they work perfectly.
But for some reason when Ansible push both in one-line instead multiple
lines.*
*To try and fix that I changed my code to this:*
---
- name: Multi-line shell
win_shell: |
## Creating Scopes
Add-DhcpServerv4Scope -Name "{{ hebrew_site_name }}" -StartRange "{{
DHCP_computers_segment }}.61" -EndRange "{{ DHCP_computers_segment }}.243"
-SubnetMask "255.255.255.0" -LeaseDuration "8.00:00:00"
Add-DhcpServerv4Scope -Name "{{ hebrew_site_name }} טלפוניה" -StartRange "{{
DHCP_telephony_segment }}.61" -EndRange "{{ DHCP_telephony_segment }}.243"
-SubnetMask "255.255.255.0" -LeaseDuration "8.00:00:00"
But then I received this error:
2020-02-23 13:43:32,770 p=54678
u=ansible n=ansible | PLAY [--------------- Creating VLAN 2,5
IP pools on dhcp1 ---------------] ********************
2020-02-23 13:43:32,784 p=54678
u=ansible n=ansible | TASK [set_fact]
***********************************************************************************
2020-02-23 13:43:32,802 p=54678 u=ansible n=ansible | ok: [dhcp-test]
2020-02-23 13:43:32,807 p=54678
u=ansible n=ansible | TASK [include_vars]
*******************************************************************************
2020-02-23 13:43:32,826 p=54678 u=ansible n=ansible | ok: [dhcp-test]
2020-02-23 13:43:32,830 p=54678
u=ansible n=ansible | TASK [include_role : new_branch]
******************************************************************
2020-02-23 13:43:32,852 p=54678 u=ansible n=ansible | ERROR! Syntax Error
while loading YAML.
did not find expected key
The error appears to be in
'/etc/ansible/roles/new_branch/tasks/dhcp1_add_pools.yml': line 5, column 7
, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
## Creating Scopes
Add-DhcpServerv4Scope -Name "{{ hebrew_site_name }}" -StartRange
"{{ DHCP_computers_segment }}.61" -EndRange
"{{ DHCP_computers_segment }}.243" -SubnetMask "255.255.255.0"
-LeaseDuration "8.00:00:00"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
2020-02-23 13:43:32,853 p=54678
u=ansible n=ansible | PLAY RECAP
****************************************************************************************
2020-02-23 13:43:32,853 p=54678
u=ansible n=ansible | dhcp-test : ok=2 changed=0
unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
*Any suggestions? Why is this happening? it should be pretty straight
forward.*
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/24ab4a52-1113-41f2-bf33-aa3e1ccb4b6a%40googlegroups.com.