假设我执行以下操作.
$ cat test.sh
#!/bin/bash
echo Hello World
exit 0
$ cat Hello.yml
---
- hosts: MyTestHost
tasks:
- name: Hello yourself
script: test.sh
$ ansible-playbook Hello.yml
PLAY [MyTestHost] ****************************************************************
GATHERING FACTS ***************************************************************
ok: [MyTestHost]
TASK: [Hello yourself] ********************************************************
ok: [MyTestHost]
PLAY RECAP ********************************************************************
MyTestHost : ok=2 changed=0 unreachable=0 failed=0
$
Run Code Online (Sandbox Code Playgroud)
我确信它是成功的.
在远程主机(MyTestHost)上我的脚本在哪里/如何看到"Hello World"回显/打印?还是脚本的返回/退出代码?
我的研究表明,我可以编写一个插件来拦截模块执行回调或者那些行上的东西并编写一个日志文件.我宁愿不浪费我的时间.
例如下面的stdout(注意我运行的是ansible而不是ansible-playbook):
$ ansible plabb54 -i /project/plab/svn/plab-maintenance/ansible/plab_hosts.txt -m script -a ./test.sh
plabb54 | success >> {
"rc": 0,
"stderr": "",
"stdout": "Hello World\n"
}
$
Run Code Online (Sandbox Code Playgroud) 所以这是使用curl的请求:
curl -XPOST -H content-type:application/json -d "{\"credentials\":{\"username\":\"username\",\"key\":\"key\"}}" https://auth.api.rackspacecloud.com/v1.1/auth
Run Code Online (Sandbox Code Playgroud)
我一直试图用ruby做同样的请求,但我似乎无法让它工作.
我也尝试了几个库,但我无法让它工作.这是我到目前为止所拥有的:
uri = URI.parse("https://auth.api.rackspacecloud.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/v1.1/auth")
request.set_form_data({'credentials' => {'username' => 'username', 'key' => 'key'}})
response = http.request(request)
Run Code Online (Sandbox Code Playgroud)
我得到415不支持的媒体类型错误.
无法更新生产服务器上的gem.
我试着bundle install --deployment和bundle install --without development test
但继续得到:
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the Gemfile freeze
by running `bundle install --no-deployment
Run Code Online (Sandbox Code Playgroud)
我不知道这是否正确,但需要快速修复.我跑了bundle install --no-deployment然后bundle update又跑bundle install --deployment了
我有一本不同名字的字典
vars:
images:
- foo
- bar
Run Code Online (Sandbox Code Playgroud)
不,我想检查存储库,然后仅在源已更改时才构建docker镜像.由于获取源和构建图像的所有项目都是相同的,除了我创建任务的名称,with_items: images
并尝试使用以下内容注册结果:
register: "{{ item }}"
Run Code Online (Sandbox Code Playgroud)
并尝试过
register: "src_{{ item }}"
Run Code Online (Sandbox Code Playgroud)
然后我尝试了以下条件
when: "{{ item }}|changed"
Run Code Online (Sandbox Code Playgroud)
和
when: "{{ src_item }}|changed"
Run Code Online (Sandbox Code Playgroud)
这总是导致 fatal: [piggy] => |changed expects a dictionary
那么如何根据迭代的列表正确保存变量名中的操作结果呢?
更新:我希望有类似的东西:
- hosts: all
vars:
images:
- foo
- bar
tasks:
- name: get src
git:
repo: git@foobar.com/repo.git
dest: /tmp/repo
register: "{{ item }}_src"
with_items: images
- name: build image
shell: "docker build -t repo ."
args:
chdir: /tmp/repo
when: "{{ …Run Code Online (Sandbox Code Playgroud) 我试图用这种方式制作一个简单的Vector类(数学):
template <int D, typename T = float>
class Vector
{
T m[D];
// ...
};
Run Code Online (Sandbox Code Playgroud)
D维数在哪里.如果是2,则向量将存储两个类型的值T.
如何声明构造函数以获取D类型的参数T?
Vector<2> v(1.0f, -6.3f);
Run Code Online (Sandbox Code Playgroud)
D如果特定号码,如何添加功能?我希望添加GetX()if D> = 1,GetY()如果D> = 2且GetZ()if D> = 3,但以下代码应生成编译时错误:
Vector<2> v(1.0f, -6.3f);
cout << v.GetZ() << endl;
Run Code Online (Sandbox Code Playgroud)
如果D <1,如何生成编译时错误?
我没有遵循任何具体的标准,任何事都适合我.
正如主题所说.我在主机清单文件中定义了一些主机变量.如何在我的剧本中访问它们?
这是一个例子.基于我所有的研究,我期待foo并bar成为其中的一部分hostvars.我可以将主机特定变量放在单独的var文件中,但我希望将它们保存在我的库存文件"附加"到主机中.我不想在模板中使用它.ansible版本:1.3.2,ansible_distribution_version:6.4
bash $
bash $ ansible --version
ansible 1.3.2
bash $
bash $ cat test_inv.ini
[foobar]
someHost foo="some string" bar=123
someOtherHost foo="some other string" bar=456
bash $
bash $ cat test.yml
---
- name: test variables...
hosts: all
vars:
- some_junk: "1"
# gather_facts: no # foo and bar are unavailable whether I gather facts or not.
tasks:
- debug: msg="hostvars={{hostvars}}"
- debug: msg="vars={{vars}}"
- debug: msg="groups={{groups}}"
- debug: msg="some_junk={{some_junk}}"
# - debug: …Run Code Online (Sandbox Code Playgroud) PS:我确实知道如何正确清理,而不依赖于finalize().
Java不保证在程序退出时,会进行适当的垃圾收集吗?
例如,假设我已经将一些数据保存在缓存中而不是频繁地将其序列化,我还finalize()希望如果由于任何原因(除了崩溃)我的程序正常退出,那么缓存将被写入DB/file/some - 我的代码在finalize()方法中存储.但根据以下小实验,似乎JVM不会"优雅地"清理内存,它只是退出.
Java规范(参见程序退出)说明了退出时如何处理内存/ gc.或者我应该查看规范的不同部分?
在Windows 7上使用1.6.0.27 64位获取以下示例(最后输出)
public class Main {
// just so GC might feel there is something to free..
private int[] intarr = new int[10000];
public static void main(String[] args) {
System.out.println("entry");
Main m = new Main();
m.foo();
m = new Main();
// System.gc();
m.foo();
m = null;
// System.gc();
System.out.println("before System.exit(0);");
System.exit(0);
}
@Override
protected void finalize() throws Throwable {
System.out.println("finalize()");
super.finalize();
}
public void foo() { System.out.println("foo()"); …Run Code Online (Sandbox Code Playgroud) 正如标题所说.
总的来说,我最近比JSON更喜欢YAML.我使用JSON在第几天实现了RESTful WS PoC.我想知道我是否可以改用YAML.
例如,有足够的工具/库/支持吗?或者我最终会做一些平凡/乏味的编码,如果我使用JSON,我会避免这种编码?
另外正如我从WWW所理解的那样:REST不限制使用YAML作为有效载荷,这是正确的吗?
谢谢!
int *arr = (int*) malloc(100*sizeof(int));
int *arr_copy = (int*) malloc(100*sizeof(int));
srand(123456789L);
for( int i = 0; i < 100; i++) {
arr[i] = rand();
arr_copy[i] = arr[i];
}
// ------ do stuff with arr ------
// reset arr...
std::copy(arr_copy, arr_copy+100, arr);
Run Code Online (Sandbox Code Playgroud)
在编译时,我得到以下警告std::copy():
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2227):
warning C4996: 'std::_Copy_impl': Function call with parameters that may be
unsafe - this call relies on the caller to check that the passed values are
correct. To disable this warning, …Run Code Online (Sandbox Code Playgroud) 我对速度非常满意,aws cli但似乎无法找到一种方法来找出文件/文件夹上的权限。
例如我这样做:
$ curl http://my.s3.amazonaws.com/deploy/tool1/license.key -o ./license.key
$ cat license.key | sed 's/></>\n</g'
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>E4D50F0606FFFD48</RequestId>
<HostId>+xxxyyyaaaa=</HostId>
$
$
Run Code Online (Sandbox Code Playgroud)
现在curl http://my.s3.amazonaws.com/deploy/tool1/tool.sh -o ./tool.sh工作正常,我可以得到tool.sh. 所以我怀疑权限license.key是问题所在。