首先与Ansible一起旋转,我正在尝试做一个相对基本的事情。我创建了一个Jinja2模板,以输出Nexus交换机的配置。似乎工作正常。我遵循的文件夹结构是,顶层目录是“角色”,该目录内是“任务”,“模板”和“变量”的子目录。据我所知,在“ vars”目录下有一个名为main.yml的文件。我想拥有多个包含各种不同元素的vars文件,以便使整个组件更具模块化。
以下是我目前拥有的一些配置:
我在顶层目录中运行的剧本:
---
- name: Apply tor role
gather_facts: no
hosts: localhost
roles:
- tor
tor / tasks / main.yml文件
- name: Generate Configs
template: src={{ item.profile }}.j2 dest=staging/drc/{{ item.hostname }}/{{ item.hostname }}.cfg
with_items: "{{ switches }}"
以及vars目录中的main.yml文件的片段:
---
switches:
- hostname: 5K01
profile: nxos_template
mgmt_ip: 10.20.90.9/24
vlans:
- {vlan_name: LegacyData, vlan_number: '5'}
- {vlan_name: Voice, vlan_number: '20'}
- {vlan_name: Data_Center, vlan_number: '50'}
- {vlan_name: Vmotion, vlan_number: '51'}
- {vlan_name: Citrix, vlan_number: '52'}
- {vlan_name: Citrix_XEN, vlan_number: '56'}
- {vlan_name: Citrix_Green_Infrastructure, vlan_number: '61'}
- {vlan_name: Citrix_Red_Ingrastructure, vlan_number: '62'}
- {vlan_name: Citrix_Green_XenApp, vlan_number: '63'}
- {vlan_name: Citrix_Yellow, vlan_number: '64'}
- {vlan_name: Citrix_Red_Desktops, vlan_number: '68'}
- {vlan_name: Zerto-VRA-Network, vlan_number: '90'}
- {vlan_name: Management, vlan_number: '92'}
- {vlan_name: PCI_FW_Intermediate_Network, vlan_number: '121'}
features:
- nxapi
- interface-vlan
- hsrp
- lacp
- vpc
- eigrp
- npiv
- fcoe
- fport-channel-trunk
- dhcp
- fex
- lldp
我想将vlans:dict删除到另一个名为vlans.yml的vars文件中。我想将其放置在与当前main.yml vars文件相同的目录中,并在某个地方调用vlans.yml文件。我曾尝试使用'include_vars:'选项,但不会使用,特别是当它与'template:'动作在同一块中使用时,给我一个错误。
答案 0 :(得分:0)
回答您的问题,是的。您可以将这些信息毫无问题地移动到新文件中。
假设您有一个main.yml和vlans.yml vars文件,这是您发布时的剧本:
tor
这应该是您的文件结构:
vlans.yml
对于角色- name: include vlans variable file
include_vars: vars/vlans.yml
- name: Generate Configs
template: src={{ item.profile }}.j2 dest=staging/drc/{{ item.hostname }}/{{ item.hostname }}.cfg
with_items: "{{ switches }}"
,您需要导入FROM python:3
ADD feature.py /
RUN pip install pandas
RUN pip install numpy
CMD ["python", "/feature.py"]
个变量:
import os # I am not sure we are going to do import right here???
import pandas as pd
import numpy as np
import sys
def freesurfer_statistics(address):
df_asseg = []
data = pd.read_csv(address+'/'+'/stats/aseg.stats', sep = '#').loc[79:]
['Unnamed: 0']
patient = pd.DataFrame()
for i in range(79,124):
patient = patient.append(data[i].split())
data = pd.DataFrame(np.array(patient).reshape(45,10))
data.columns = ['Index','SegId','NVoxels','Volume_mm3',\
'StructName','normMean','normStdDev','normMin','normMax','normRange']
df_asseg.append(list(data.NVoxels)+list(data.Volume_mm3)+ list(data.normMean)+list(data.normStdDev)+list(data.normMin)+list(data.normMax)+list(data.normRange))
df_asseg = pd.DataFrame(np.array(df_asseg).reshape(1,315))
df_rh = pd.DataFrame(np.array(df_rh).reshape(1,306))
df_rh.columns = names
csv_file=pd.concat([df_asseg, df_rh, df_lh], axis = 1)
csv_file.to_csv(address+'/morphometry.csv')
freesurfer_statistics(sys.argv[1])