Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
pabu
Participant
Participant

Ansible playbook, error add network AND host

Hi all,

I just started playing with Ansible. I Needs some help. I build a test setup:
- Using: ansible-galaxy collection install check_point.mgmt, v1.0.6
- Smartcenter R80.40, latest jumbo

Everything is working, I am able to create a network object using a playbook. My working example:

----------- WORKING PLAYBOOK -----------

- name: playbook name
hosts: check_point
connection: httpapi
tasks:
- name: This is the first network
cp_mgmt_network:
name: "TEST"
subnet: 1.1.1.0
mask_length: 24
cp_mgmt_network:
name: "TEST2"
subnet: 2.2.2.0
mask_length: 24
auto_publish_session: true

---------------------------------------------------

Now my challenge, I would like to extend this playbook to add also a host object. My new script: 

------------ FAILED PLAYBOOK --------------------

- name: playbook name
hosts: check_point
connection: httpapi
tasks:
- name: "Test with two Check Point networks"
cp_mgmt_network:
name: "TEST"
subnet: 1.1.1.0
mask_length: 24
cp_mgmt_network:
name: "TEST2"
subnet: 2.2.2.0
mask_length: 24
- name: "Add a new host object"
cp_mgmt_host:
name: "Test3"
ip_address: 3.3.3.3

-----------------------------------------------------

Error output: 

ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator

The error appears to be in '/etc/ansible/test.yml': line 14, column 6, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

mask_length: 24
- name: "Add a new host object"
^ here

-----------------------------------------------------

Could you please assist? I am really new to ansible. 

Thanks!!!

Regards, Paul

0 Kudos
11 Replies
PhoneBoy
Admin
Admin

It would be helpful if you attached the exact script used.
Indents matter quite a bit and it’s difficult to see with what was pasted to the community.

0 Kudos
pabu
Participant
Participant

Added two files, the faulty script and the error output. 

0 Kudos
funkylicious
Advisor

Hi,

Please try and add a empty line between the tasks of network creation and host creation.

 

0 Kudos
pabu
Participant
Participant

Hi,

Thanks for your help! Still not working with a empty line. 

Regards, Paul

0 Kudos
funkylicious
Advisor

Hi,

Based on this and SK
try:

 

- name: add-host
  cp_mgmt_host:
    ip_address: 192.0.2.1
    name: New Host 1
    state: present

 

 

0 Kudos
pabu
Participant
Participant

Dear funkylicious,

Still not working. The add-host is working if I am using it in a playbook alone. When I combine it with the cp_mgmt_network I get errors. I added the script and output below.

Regards, Paul

---------------------------------------------------------------------

@ansible01:/etc/ansible# cat test2.yml
---
- name: playbook name
hosts: check_point
connection: httpapi
tasks:
- name: "Test with two Check Point networks"
cp_mgmt_network:
name: "TEST"
subnet: 1.1.1.0
mask_length: 24
cp_mgmt_network:
name: "TEST2"
subnet: 2.2.2.0
mask_length: 24

- name: add-host
cp_mgmt_host:
ip_address: 192.8.2.1
name: New host
state: present

---------------------------------------------------------------------
root@ansible01:/etc/ansible# ansible-playbook test2.yml
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator

The error appears to be in '/etc/ansible/test2.yml': line 16, column 6, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: add-host
^ here

---------------------------------------------------------------------

0 Kudos
funkylicious
Advisor

Hi,

Sorry, but i didn't pay enough attention to your playbook/details.

Apparently, from my understanding you cannot combine multiple modules in the same playbook, e.g cp_mgmt_network and cp_mgmt_host , so you would require individual playbooks for different tasks/modules.

If I misread/misunderstood this, someone please correct me.

pabu
Participant
Participant

Ow really, are you sure about this? Should explain a lot :-)!

0 Kudos
pabu
Participant
Participant

Hi,

Its working when I use seperate playbooks, one for each module. For example: 

main-playbook.yml
- import_playbook: playbook-add-network-objects.yml
- import_playbook: playbook-add-host-objects.yml

Regards, Paul

Daniel_Schlifka
Contributor

Well, theres a yaml syntax error. see attached screenshot and fix the indent in the according line.

pabu
Participant
Participant

Thanks!!! I dont understand whats wrong in the syntax, should be OK? 

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events