小编Nis*_*ngh的帖子

如何使用boto3获取公共IP

我需要从 AWS 中提取所有 RUNNING PUBLIC Ip,我正在使用以下代码:

def gather_public_ip():
    regions = ['us-west-2', 'eu-central-1', 'ap-southeast-1']
    combined_list = []   ##This needs to be returned
    for region in regions:
        instance_information = [] # I assume this is a list, not dict
        ip_dict = {}
        client = boto3.client('ec2', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY,
                              region_name=region, )
        instance_dict = client.describe_instances().get('Reservations')
        for reservation in instance_dict:
            for instance in reservation['Instances']: # This is rather not obvious
               if instance[unicode('State')][unicode('Name')] == 'running' and instance[unicode('PublicIpAddress')] != None:
                    ipaddress = instance[unicode('PublicIpAddress')]
                    tagValue = instance[unicode('Tags')][0][unicode('Value')] # 'Tags' …
Run Code Online (Sandbox Code Playgroud)

python boto3

3
推荐指数
1
解决办法
9170
查看次数

如何在ansible中解析URI的XML响应

有一个代码可以调用应用程序的 Web 服务。

 - uri:
         url: http://10.164.52.61:8080/ems/v74/ws/customer.ws?customerRefId=f4XXXb15d69c3
         method: GET
         content_as_json: true
         password: admin
         user: admin
         validate_certs: no
         return_content: yes
         HEADER_Cookie: "{{login.set_cookie}}"
        register: customerId

      - debug:
          var: customerId.content
Run Code Online (Sandbox Code Playgroud)

样本响应是

"customerId.content": "<listResponse type=\"customer\" count=\"1\"><instance customerId=\"28\" name=\"abc\" customerRefId=\"xyz\" refId1=\"12\" type=\"org\" enabled=\"true\" phone=\"\" fax=\"\" billingZip=\"\" billingAddress=\"\" billingCity=\"\" billingCountry=\"\" billingState=\"\" vendor=\"1\" defaultEmail=\"test\" defaultContactName=\"test\"/></listResponse>"
Run Code Online (Sandbox Code Playgroud)

我想在下一个代码块中访问列表响应。就像我只需要“customerId”的值。如何使用 anisble 实现这一点

ansible ansible-playbook

3
推荐指数
1
解决办法
1万
查看次数

How to redirect to multiple servers sitting behind HAProxy which have different path begining

I have 3 servers which listen on following port ,

> 10.21.5.39:80    -->   api.something.com
> 10.21.4.234:80    -->   *.something.com
> 10.21.5.73:80     -->   coolapi.something.com
> 10.21.5.73:3002    -->   school.something.com
Run Code Online (Sandbox Code Playgroud)

I am using a HAProxy server to redirect the traffic to these backends, i am using the following config on haproxy which doesn't seem to workout.

frontend api
       bind *:80
       acl url_api path_beg /api
       use_backend api-backend if url_api

frontend custui
       bind *:80
       acl url_custui path_beg *
       use_backend custui-backend if url_custui


frontend backoffice
       bind *:80 …
Run Code Online (Sandbox Code Playgroud)

routing load-balancing haproxy

3
推荐指数
1
解决办法
1万
查看次数

如何将 os.system() 的输出存储在变量中

我写了一个小代码:

import os
os.system('users')
os.system('w')
Run Code Online (Sandbox Code Playgroud)

这打印

ubuntu
 09:27:25 up 9 days, 21:23,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/0    42.99.164.66     09:06    5.00s  0.10s  0.00s sh -c w
Run Code Online (Sandbox Code Playgroud)

但是当我尝试:

import os
from pyslack import SlackClient

user_name = os.system('users')
login_details = os.system('w')

print user_name
print login_details
Run Code Online (Sandbox Code Playgroud)

它有以下输出:

ubuntu
 09:28:32 up 9 days, 21:24,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/0    42.99.164.66     09:06 …
Run Code Online (Sandbox Code Playgroud)

python os.system

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

无法使用 ansible 在本地进行 git clone

我正在尝试在我的本地系统上克隆一个 git repo。我已手动完成此操作并且它工作正常,但是当我尝试通过 ansible 执行此操作时,它不起作用

这是我的玩法:

---
  - name: Create a directory on root
    file:
      path: "{{ local_home_dir }}/superb-queue"
      owner: "{{ local_user }}"
      group: "{{ local_user }}"
      state: directory
    delegate_to: localhost

  - name: Clone the bitbucket queue repo locally
    git:
      repo: git@bitbucket.org:superbhq/queue-main.git
      dest: "{{ local_home_dir }}/superb-queue"
      clone: yes
      recursive: yes
      force: yes
      accept_hostkey: yes
      version: master
      key_file: "{{ local_home_dir }}/.ssh/id_rsa"
    become_user: "{{ local_user }}"
    delegate_to: localhost
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

ASK [deploy-queue-main : Clone the bitbucket queue repo locally] ******************************************************************************************************************************************
fatal: [10.0.3.219 -> …
Run Code Online (Sandbox Code Playgroud)

git ansible

3
推荐指数
2
解决办法
7600
查看次数

Ansible 错误:lxc 模块不可导入。检查要求

我的任务看起来像这样

- name: Create a started container
    lxc_container:
      name: test-container-started
      container_log: true
      template: ubuntu
      state: started
      template_options: --release trusty
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

> TASK: [lxc | Create a started container]
> **************************************  failed: [localhost] => {"failed": true, "parsed": false}
> BECOME-SUCCESS-azsyqtknxvlowmknianyqnmdhuggnanw failed=True msg='The
> lxc module is not importable. Check the requirements.' The lxc module
> is not importable. Check the requirements.
> 
> 
> FATAL: all hosts have already failed -- aborting
Run Code Online (Sandbox Code Playgroud)

ansible devops

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

如何在HAproxy上应用csr certi?

我从我的CA获得了一些证书,如下所示

1. something.csr
2. something.zip --> contains 2 .cert files.
Run Code Online (Sandbox Code Playgroud)

我正在使用HAProxy并希望应用它们.Haproxy已经使用.pem证书,那么我如何转换/组合上面提到的证书来获得一个.pem文件?

certificate haproxy

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

有没有一种方法可以“不”使用 AWS 凭证向 Amazon SQS 发送消息?

我的应用程序需要将消息发送到 sqs 队列。boto.sqs.connect_to_region()我可以使用http://boto.cloudhackers.com/en/latest/sqs_tut.html轻松完成所需的操作。这个想法非常简洁[这里没有问题]

最近我意识到需要在不使用AWS密码的情况下发送数据。我想知道如何在不提供凭据的情况下将数据发送到 AWS SQS。

我还读到: https: //github.com/chilts/awssum/issues/48

有人可以告诉我如何在没有信用的情况下执行简单的 SQS 推送吗?最近我认为答案可以围绕 IAM 角色(某些策略相关或角色)或 SQS 队列创建。

帮帮兄弟吧:)

amazon-sqs amazon-web-services

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

Sorted 方法在 3.x python 中的工作方式与 2.x 不同

我正在尝试测试以下内容:

在 Python 2.x 中,排序工作正常:

>>> sorted([{'callme': 'voyaps-ai-job', 'breakme': 'folld-qy'}, {'callme': 'mixerjui', 'breakme': 'folld-ry'}, {'callme': 'voyaps-ml-jobs', 'breakme': 'folld-uy'}])
[{'breakme': 'folld-qy', 'callme': 'voyaps-ai-job'}, {'breakme': 'folld-ry', 'callme': 'mixerjui'}, {'breakme': 'folld-uy', 'callme': 'voyaps-ml-jobs'}]
Run Code Online (Sandbox Code Playgroud)

在 3.X 这打破了

>>> sorted([{'callme': 'voyaps-ai-job', 'breakme': 'folld-qy'}, {'callme': 'mixerjui', 'breakme': 'folld-ry'}, {'callme': 'voyaps-ml-jobs', 'breakme': 'folld-uy'}])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'dict' and 'dict'
Run Code Online (Sandbox Code Playgroud)

即我不能调用排序这种数据。我该怎么做才能做到这一点?

python python-3.x

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