将CSV文件中的值传递到Ansible playbook
下面的文件是我的剧本、目录和CSV文件(我的字典) 网络对象.yml将CSV文件中的值传递到Ansible playbook,csv,ansible,checkpoint,Csv,Ansible,Checkpoint,下面的文件是我的剧本、目录和CSV文件(我的字典) 网络对象.yml --- - hosts: all connection: httpapi gather_facts: False vars_files: - 'my_var.yml' tasks: - name: add-host check_point.mgmt.cp_mgmt_host: name: New Host 1 ip_address: 192.0.2.1
---
- hosts: all
connection: httpapi
gather_facts: False
vars_files:
- 'my_var.yml'
tasks:
- name: add-host
check_point.mgmt.cp_mgmt_host:
name: New Host 1
ip_address: 192.0.2.1
state: present
auto_publish_session: yes
- name: add-group
check_point.mgmt.cp_mgmt_group:
name: New Group 1
members:
- New Host 1
state: present
auto_publish_session: yes
ansible_httpapi_validate_certs: False
ansible_httpapi_use_ssl: True
ansible_network_os: check_point.mgmt.checkpoint
ansible_python_interpreter: "python3"
ansible_user: admin
ansible_password: password
我的变量yml
---
- hosts: all
connection: httpapi
gather_facts: False
vars_files:
- 'my_var.yml'
tasks:
- name: add-host
check_point.mgmt.cp_mgmt_host:
name: New Host 1
ip_address: 192.0.2.1
state: present
auto_publish_session: yes
- name: add-group
check_point.mgmt.cp_mgmt_group:
name: New Group 1
members:
- New Host 1
state: present
auto_publish_session: yes
ansible_httpapi_validate_certs: False
ansible_httpapi_use_ssl: True
ansible_network_os: check_point.mgmt.checkpoint
ansible_python_interpreter: "python3"
ansible_user: admin
ansible_password: password
主机
[check_point]
checkpoint ansible_host=#IP address of checkpoint
users.csv
Name,IP Address,Comments
PCUSER1,10.11.92.44, Created by User Feb 19 2021
PCUSER2,10.11.12.13, Created by User 02/19/2012
readCSV.yml-->这将读取名为users.csv的csv文件
- name: "Check for CSV File"
hosts: localhost
gather_facts: no
tasks:
- name: Read CSV File and Return a dictionary
read_csv:
path: users.csv
key: name
register: user
- ansible.builtin.debug:
msg: '{{ user }}
我想要实现的
我希望能够读取我的CSV,并按照CSV数据列出的顺序传递这些变量。然后我可以将新主机(包含所有名称、IP地址和注释)发布到检查点
- name: add-host
check_point.mgmt.cp_mgmt_host:
name: {{ Get all Names from CSV File }}
ip_address: {{ Get all IP Addresses from CSV File }}
comments: {{ Get all Comments from CSV File }}
我不确定它的价值。
我认为user的输出是{user:[ip_地址,comments],…}
看看你的口述结构,我认为我的目的是好的,但要适应它
source对于循环,使用循环:{user.dict | dict2items}}``-name:add host check_point.mgmt.cp_mgmt_host:name:{{item.value.name}}ip地址:{{item.value.ip}注释:{item.value.comments}}循环:{{user{dict2item}dict2items}``对于循环,使用循环:{user.dict2item}```-name:add host check_point.mgmt.cp_mgmt_host:name:{{item.value.name}}ip_地址:{{item.value.ip}注释:{{item.value.comments}循环:{{user}dict2items}```