在Ansible 1.7中,我可以使用命令行中的--tags来运行该playbooks任务的子集.
但是我想要在我的剧本中加入一套角色,只运行与标签相匹配的任务.也就是说,我不想通过命令行传递它,因为它每次都是相同的.
起初我以为是这个命令,但这恰恰相反:使用这些标记标记任务而不是基于此过滤掉它们.
roles:
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
Run Code Online (Sandbox Code Playgroud)
我可以想象使用条件实现它,但标签将是一种更优雅的方式来实现这一点.
我正在编写一个简单的Perl脚本,它将汇编指令字符串转换为32位二进制代码.
我决定按类型处理翻译分组指令(ADD并且SUB是R-Type指令等等)所以在我的代码中我做的是这样的:
my $bin = &r_type($instruction) if $instruction =~ /^(?:add|s(?:ub|lt|gt))\s/;
Run Code Online (Sandbox Code Playgroud)
因为我要处理add,sub,slt并sgt以同样的方式.
然而我意识到,使用那个正则表达式对于我应该做的任务可能是一个"过度杀伤"...可能是模式
/^(?:add|sub|slt|sgt)\s/
Run Code Online (Sandbox Code Playgroud)
在这种情况下代表更好地使用正则表达式?
非常感谢.
我正在尝试使用正则表达式从SQL导出文件中转储数据.为匹配帖子内容的字段,我使用' (?P<content>.*?)'.它在大多数情况下工作正常,但如果字段包含'\n'字符串,则正则表达式将不匹配.如何修改正则表达式以匹配它们?谢谢!
示例(我正在使用Python):
>>> re.findall("'(?P<content>.*?)'","'<p>something, something else</p>'")
['<p>something, something else</p>']
>>> re.findall("'(?P<content>.*?)'","'<p>something, \n something else</p>'")
[]
Run Code Online (Sandbox Code Playgroud)
PS看起来前面带有'\'的所有字符串都被视为转义字符.我怎么能告诉regx按原样对待他们?
我想从一个C程序调用一个Lua脚本,该脚本是require()一个lyaml模块,Lua绑定LibYAML.
我从源代码编译了Lua 5.2,并且我修改了模块以使它与Lua 5.2一起工作.它可以在github上找到.
Lua脚本如下,它适用于Lua 5.1和5.2:
-- foo.lua
require('lyaml')
function hello ()
res = lyaml.load("a: 4\n")
return res.a
end
-- then calling hello() it works like a charm
print( hello() ) -> 4
Run Code Online (Sandbox Code Playgroud)
我写了一个C程序应该调用hello()从脚本,下面Lua中,第25章编程和Lua中5.2参考手册.
C程序如下:
/* foo.c */
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int main(void)
{
double z;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dofile(L, "foo.lua"))
luaL_error(L, "error running script: %s", lua_tostring(L, -1));
lua_getglobal(L, "hello"); …Run Code Online (Sandbox Code Playgroud) 在下面的Ruby代码中,我有两个方法d100_in_detect,d100_out_detect它们根据结果返回一个Array包含在其中的唯一元素(简称为数字).aryd100
def d100
1 + ( rand 100 )
end
def d100_in_detect( ary )
choice = [ ]
100.times do
choice.push ary.detect { |el| d100 <= el }
end
choice.uniq.sort
end
def d100_out_detect( ary )
choice = [ ]
numbers = [ ]
100.times do
numbers.push d100
end
numbers.each do |i|
choice.push ary.detect { |el| i <= el }
end
choice.uniq.sort
end
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,两种方法之间的区别在于,第一种d100是在内部detect块中调用,而在第二种中,100个随机数存储在numbers数组中,然后在发生时使用d100_in_detect.
我们假设我将这两种方法称为如下 …
例如,我想使用具有不同IP地址的两个不同域
domain1.com - 12.34.56.78
domain2.com - 98.76.54.32
Run Code Online (Sandbox Code Playgroud)
我在Linux OS上使用nginx.我应该在我的nginx.conf中添加什么?
在代码中:
<% @offers.each do |offer|%>
<%= offer.percentageOff%> <b>% OFF on order of</b>
<%= image_tag('1407951522',:size=>'10x10',:alt=>'Rs.')%>
<%= offer.amountforDiscount%>
<%= button_to 'Delete',{:action=>'destroy',:id=>offer.id},class: "" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我是铁杆新手.我想在编号列表中显示所有商品,我不能使用数据库表,因为id不按顺序.例如:
订单满£2000即可享受30%折扣
订单价格为1000卢比,折扣13%
我如何实现这一目标?
Ansible版本:2.0.0.2
我需要通过库存主机变量覆盖角色默认变量.据我所知读变量优先级:我应该在哪里放置变量?在Ansible Docs中,它是可能的,但也许它不是最佳实践,但不幸的是,有些主机必须调整一些默认配置参数.
我将重现真实案例,所以让我们考虑以下目录层次结构:
??? debug.yml
??? host_vars
? ??? test.localdomain
??? inventory
? ??? debug
??? roles
??? debug
??? tasks
? ??? main.yml
??? vars
??? main.yml
Run Code Online (Sandbox Code Playgroud)
debug.yml是我们的playbook文件.
---
- name: debug
hosts: debug
roles:
- debug
Run Code Online (Sandbox Code Playgroud)
host_vars/test.localdomain包含我想要优先于默认值的变量.
---
foo:
bar:
- hey
Run Code Online (Sandbox Code Playgroud)
库存/调试是我们将要使用的库存文件.
[debug]
test.localdomain
Run Code Online (Sandbox Code Playgroud)
roles/debug/tasks/main.yml打印出foo.bar变量.
---
- debug: msg="{{foo.bar}}"
Run Code Online (Sandbox Code Playgroud)
roles/debug/vars/main.yml包含默认角色变量.
---
foo:
bar:
- hello
- world
Run Code Online (Sandbox Code Playgroud)
此时,我希望在调试playbook运行期间,foo.bar的值是[ "hey" ],但显然我错了:
> ansible-playbook debug.yml …Run Code Online (Sandbox Code Playgroud) 我在Lua中编写了一个CLI模块,嵌入到C程序中.
我想知道什么是处理提示的最佳方法,在尾调用和循环之间进行选择.
作为尾部调用我会做这样的事情:
call = { help=function () print 'just ask politely' end }
function shell ()
io.write ('% ')
local cmd = io.read ()
if cmd ~= 'quit' then
call[cmd] () -- for simplicity assume call[cmd] is never nil
return shell ()
end
end
Run Code Online (Sandbox Code Playgroud)
我会问以下问题:
它是否正确使用/实现尾部调用消除?是否call[cmd] ()在堆栈中引入任何干扰,以便我不会利用尾部消除功能?
使用如下循环更好吗?如果是,为什么?
repeat
io.write ('% ')
local cmd = io.read()
-- do stuff
until cmd == 'quit'
Run Code Online (Sandbox Code Playgroud)在Lua的编程中说明了
一 …
这个代码一切正常,除了我得到一个未定义的变量警告'消息',我无法找到一种方法来定义它,因为它不是一个帖子或会话变量或任何东西.谢谢
<?php
if (isset($_POST['submit']))
{
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
$message="";
//open database
if (condition)
{
$message="first message";
}
}
?>
<p td class='td2'><?php echo $message;?></td>
Run Code Online (Sandbox Code Playgroud)