I'm hoping to use an Ansible playbook and use a YAML inventory file. If I use a .csv and use the mgmt_cli commands then I have to transfer that .csv to the management first. I want to avoid having any unnecessary files on the management server.
So far here is what my variables file looks like:
---
hosts:
- {host_name: "host1", ip_address: "1.1.1.1", host_color: "yellow"}
- {host_name: "host2", ip_address: "1.1.1.2", host_color: "yellow"}
And here is the relevant section from my playbook for loading the variables file and then running adding the hosts:
- name: "Adding host variables"
include_vars:
file: hosts.yml
name: hosts_file
- name: "Adding hosts to mgmt database"
check_point_mgmt:
session-data: "{{login_response}}"
command: add-host
parameters:
name: "{{item.host_name}}"
ip-address: "{{item.ip_address}}"
color: "{{item.host_color}}"
with_items:
- "{{hosts_file}}"
When I run that playbook I get the following error:
TASK [Adding host variables] ***************************************************
ok: [127.0.0.1]
TASK [Adding hosts to mgmt database] *******************************************
fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'color'\n\nThe error appears to have been in '/home/jesmith4/ansible/Playbooks/test_hosts.yml': line 22, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: \"Adding hosts to mgmt database\"\n ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'host_color'"}
I don't believe it's loading the variables properly. I've been scouring the internet looking for an answer but no luck yet. If anyone has any ideas on how to make it work let me know and I'll give it a try.