我是一名Linux管理员,只掌握Mysql查询的基本知识
我想使用id删除许多表条目,这些表条目是我的表中的ip地址,
目前我正在使用
DELETE from tablename where id=1;
DELETE from tablename where id=2;
Run Code Online (Sandbox Code Playgroud)
但我必须删除254个条目,所以这个方法需要几个小时,我怎么能告诉mysql删除我指定的行,因为我想跳过删除254中的一些条目.
删除整个表并导入所需的条目不是一种选择.
我正在使用ansible来更新新添加的NIC的配置文件,因为我已经在单独的yml文件中定义了一些变量
/tmp/ip.yml
#first interface
interface1: eth1
bootproto1: static
ipaddress1: 192.168.211.249
netmask1: 255.255.255.0
gateway: 192.168.211.2
DNS1: 192.168.211.2
#second interface
interface2: eth2
bootproto2: static
ipaddress2: 10.0.0.100
netmask2: 255.0.0.0
Run Code Online (Sandbox Code Playgroud)
剧本
- include_vars: /tmp/ip.yml
- name: configuring interface
lineinfile:
state=present
create=yes
dest=/etc/sysconfig/network-scripts/ifcfg-{{interface1}}
regexp="{{ item.regexp }}"
line="{{ item.line }}"
with_items:
- { regexp: '^BOOTPROTO=.*', line: 'BOOTPROTO={{interface1}}' }
- { regexp: '^IPADDR=.*', line: 'IPADDR={{ipaddress1}' }
- { regexp: '^NETMASK=.*', line: 'NETMASK={{netmask1}}' }
- { regexp: '^GATEWAY=.*', line: 'GATEWAY={{gateway}}' }
- { regexp: '^PEERDNS=.*', line: 'PEERDNS=no' } …Run Code Online (Sandbox Code Playgroud) 我使用" shell: "通过循环" with_items: "并将其注册为另一个变量来获取一些数据.稍后使用" lineinfile: "我试图应用早期变量的内容,但不能使用" {{variable.stdout}} ",因为它在" with_items: "中显示为未定义
有没有办法告诉ansible" variable.stdout "不要查看" with_items: "
---
- include_vars: /root/template.yml
- name: Getting MAC
shell: "cat /sys/class/net/{{item.name}}/address"
register: mac
with_items:
- "{{ interfaces_ipv4 }}"
- name: Setting MAC
lineinfile:
state=present
dest=/etc/sysconfig/network-scripts/ifcfg-{{item.name}}
regexp='^HWADDR=.*'
line="HWADDR={{mac.stdout}}"
with_items:
- "{{ interfaces_ipv4 }}"
tags:
- set_mac
Run Code Online (Sandbox Code Playgroud)
变量文件的内容
#/root/tempplate.yml
- name: ens35
bootproto: dhcp
- name: ens34
bootproto: none
Run Code Online (Sandbox Code Playgroud)
执行时:
任务:[mac | 设置MAC]***************************************************致命:[192.168.211.146] => 一个或多个未定义的变量:'dict'对象没有属性'stdout'
致命:所有主机都已经失败 - 中止
我正在尝试使用带有ipmitools的 ansible shell模块启动服务器,然后在该服务器上进行配置更改.
安装了ansible的服务器也有ipmitools.
在带有ansible的服务器上,我需要执行ipmitools来启动目标服务器,然后在其上执行playbooks.
有没有办法在运行ansible的服务器上执行本地ipmi命令,通过ansible启动目标服务器,然后在目标服务器上通过ssh执行所有playbooks.
使用spec文件创建的rpm将创建目录"directory1"和/ var/lib/directory1中的所有文件.
对于另一个用例,我想在"/ var/lib"中创建另一个目录,该目录应该是directory1的符号链接.
eg:
cd /var/lib/
ls -la
directory2 -> directory1
directory1
Run Code Online (Sandbox Code Playgroud)
如何在不使用spec文件中的绝对路径的情况下实现此目的?
试图用ansible做一个iptables-save
name: Save Netfilter Rules
action: command iptables-save > /etc/sysconfig/iptables
Run Code Online (Sandbox Code Playgroud)
但这会给出错误
failed: [10.110.211.17] => {"changed": true, "cmd": ["iptables-save", ">", "/etc/sysconfig/iptables"], "delta": "0:00:00.009345", "end": "2014-06-09 16:55:18.306375", "rc": 1, "start": "2014-06-09 16:55:18.297030"}
stderr: Unknown arguments found on commandline
Run Code Online (Sandbox Code Playgroud)
但是在ssh上这很好用:
ssh root@host "iptables-save > /etc/sysconfig/iptables"
Run Code Online (Sandbox Code Playgroud)
工作正常但不通过Ansible命令:模块
我怎样才能做到这一点