小编rob*_*ams的帖子

在ansible中使用连字符

我正在学习Ansible但是我很困惑何时使用连字符以及何时不在剧本中使用连字符.据我所知,连字符用于Ansible中的列表.

例如,

--- # my first playbook
      - hosts: webservers  ( why did we use hyphen here it is not a list)
        tasks: 
          - name: installing httpd
            yum: name=httpd state=installed ( why we shouldn't use hyphen here).
Run Code Online (Sandbox Code Playgroud)

从Ansible文档中可以看出,连字符是用于列表的,例如:

fruits:
  - apple
  - grapes
  - orange
Run Code Online (Sandbox Code Playgroud)

所以,我很困惑什么时候使用连字符和何时不使用.

configuration-management ansible ansible-playbook devops

7
推荐指数
1
解决办法
3575
查看次数

如何确定_POSIX_PATH_MAX的系统值

任何人都可以请告诉我如何找到_POSIX_PATH_MAXLinux薄荷的系统值?我知道它可以在<limits.h>文件中找到,但我不知道如何找到它的值.

c unix kernel linux-kernel linux-mint

5
推荐指数
1
解决办法
1587
查看次数

Ansible中的冲突动作声明

我收到以下错误:Conflicting action statement in ansible

我试图理解,我的代码似乎是正确的。我正确地声明了名称,尽管它在任务名称中给出了错误。

---
 - hosts: webhost
   sudo: yes
   connection: ssh

   tasks:
    - name: debuging module
      shell: ps aux
      register: output
      debug: var=output
Run Code Online (Sandbox Code Playgroud)

ERROR! conflicting action statements

该错误似乎出现在“ /home/test/playbooks/debug.yml”中:第7行,第7列,但根据确切的语法问题,该错误可能出现在文件的其他位置。

令人讨厌的行似乎在这里:

   tasks:
    - name: debuging module
      ^ here
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook ansible-2.x

4
推荐指数
1
解决办法
7554
查看次数

没有与此分配匹配的代理/云 - jenkins 错误

当我尝试创建作业时,我正在尝试分配一个从节点,但我收到错误消息“没有与此分配匹配的代理”。但我创建了一个名为“Linux_slave1”的节点,我的 Jenkins 能够连接到从站。 配置作业时出错 Jenkins 与 Linux_slave1 通信

jenkins jenkins-plugins

4
推荐指数
1
解决办法
3615
查看次数

在实例变量和局部变量之间混淆

我最近开始学习ruby,我在实例变量和局部变量以及类变量之间感到困惑.所以,我最近编写的代码将找到1000个素数中最大的回文数.代码是:

def prime_large(number)
  arr_prime = []
  Prime.each(number) do |x|
    new_arr_prime = arr_prime.push(x.to_s)
    updated = new_arr_prime.select { |y| y.reverse == y }
  end
  p updated.max 
end
p prime_large(1000)
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

undefined local variable or method `updated' for main:Object (NameError)
Run Code Online (Sandbox Code Playgroud)

我知道更新是素数的局部变量所以我不能在它之外访问它但我通过用@updated替换它来改变代码如下:

def prime_large(number)
  arr_prime = []
  Prime.each(number) do |x|
    new_arr_prime = arr_prime.push(x.to_s)
    @updated = new_arr_prime.select { |y| y.reverse == y }
  end
  p @updated.max 
end
p prime_large(1000)
Run Code Online (Sandbox Code Playgroud)

更改后,我得到了输出:

"929"
"929"
Run Code Online (Sandbox Code Playgroud)

在我的代码中,没有创建一个类,我的实例变量(@updated)是如何工作的.我在本地变量和实例变量之间感到困惑.任何人都可以解释我的差异和他们的工作方式吗?

ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-4

4
推荐指数
1
解决办法
145
查看次数

python 列表推导式中的 if-else

是否可以为以下 python 代码编写列表推导式:

for str in range(0,len(mixed_content)):
    if (mixed_content[str].isdigit()):
        num_list.append(mixed_content[str])
    else:
        string_list.append(mixed_content[str])
Run Code Online (Sandbox Code Playgroud)

我们可以在列表推导式中使用 else 块吗?我尝试为上述代码编写列表推导式:

num_list , string_list = [   mixed_content[str]  for str in range(0,len(mixed_content)) if(mixed_content[str].isdigit()) else ]
Run Code Online (Sandbox Code Playgroud)

python list-comprehension python-2.7 python-3.x

2
推荐指数
1
解决办法
854
查看次数

我想创建一个乘法表矩阵

我想创建一个由前12个乘法表组成的矩阵。

到目前为止,我的代码是:

x = range(1,13,1)
n = range(1,13,1)

list_to_append = []
list_for_matrix = []

for i in x:

    for j in n:

        list_to_append.append(i*j)

list_for_matrix.append(list_to_append[0:12])
list_for_matrix.append(list_to_append[12:24])
list_for_matrix.append(list_to_append[24:36])


print (list_to_append)
print (list_for_matrix)
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 5, …
Run Code Online (Sandbox Code Playgroud)

python ipython python-2.7 python-3.x

0
推荐指数
1
解决办法
636
查看次数

Linux BASH脚本确定登录的用户数量?

我需要帮助编写BASH脚本,通过获取系统密码文件中包含的密码数来确定系统的潜在用户数.我试过/ etc/passwd.总是说"权限被拒绝".以及确定当前登录到系统的用户数的脚本.此脚本将以无人参与的批处理方式运行,除了被调用之外没有来自键盘的任何输入.

谢谢.

unix linux bash ubuntu

-1
推荐指数
1
解决办法
9396
查看次数