亲爱的社区,我请求您的帮助。
我会创建一个游戏手册,它将使用输入中给定的宏地址,并且应该尊重Unix格式。然后,如果给定的地址符合所需的格式,则另一个任务将检查给定的宏地址是否与主机中的已存在的地址匹配,**如果不存在,它将显示the interface related to that macaddress (如果没有),任务将失败,并带有错误消息"No interfaces found with mac address '$MACADDRESS'. Fatal error."。
以下是我所做的,我不知道应该做些什么来实现这个目标:
- hosts: all
经过研究,我发现在windows下获取以太网MAC地址的最好方法是使用"getmac“命令。( python的getmac模块不会产生同样的结果!!)。现在,我想在python代码中使用此命令来获取MAC地址。我计算出我的代码应该像这样开始:
import os
if sys.platform == 'win32':
os.system("getmac")
do something here to get the first mac address that appears in the results
下面是一个输出示例
Physica
我正在处理一个7 PCAP文件,方法是根据MAC地址拆分该文件。这很好,但我有各种变量需要遍历
${macs*} -我有10个不同MAC地址的列表,我想遍历它们${ devices } -我有10个设备的列表,例如Samsung、Phillips,我想在每个文件中添加一个数字
for pcf in $pcap_file
do
for mac in ${macs[*]}
do
echo "$mac" >&2
/usr/bin/tshark -r "$pcf" -Y "eth.addr eq
我的问题是如何最好地将主机/角色应用于Ansible中的不同操作系统。
我目前正在使用Ansible来生成Windows/Mac/Linux,每个‘m都有不同的角色需要应用于它们。
我已经阅读了最佳实践,并试图遵循它们,特别是使用分组方法,但我仍然不确定,因为它们大多提到了webserver和dbserver。
site.yml
- name: Apply common configuration to all nodes
hosts: all
roles:
- common
- name: Configure and deploy test node 1
hosts:
如何删除下面剧本输出列表中的空行?然后,我只需要在变量中存储mac地址和端口信息,可以在ansible it self中删除它,还是需要使用任何其他方法?
剧本,
- name: Print Converted Mac
set_fact:
mac_array: "{{ sw_mac.results | json_query('[*].stdout') }}"
- name: Query the mac on the switch
ios_command:
commands: show mac address-table | in {{
代码:
$_ = "Sample sentence with 00-B0-D0-86-BB-F7 MAC address in the middle";
my ($a, $mac, $b) =
split('/([0-9A-F]{2}[:-]){5}([0-9A-F]{2})/', $_);
print $mac;
print "\n";
由于某些原因,$mac总是空的,我不知道为什么。