Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible尝试使用社区AWS模块查询AWS TG以获取TG状态_Ansible - Fatal编程技术网

Ansible尝试使用社区AWS模块查询AWS TG以获取TG状态

Ansible尝试使用社区AWS模块查询AWS TG以获取TG状态,ansible,Ansible,我正在尝试使用来查询AWS TG以获取TG状态, 我想每隔几秒钟查询一次特定的TG,直到我看到该TG的状态为“健康” 到目前为止,我的任务是: - name: Gather information about the target group attached to a particular LB vars: ansible_python_interpreter: /usr/bin/python3.6 register: target_health community.aws

我正在尝试使用来查询AWS TG以获取TG状态, 我想每隔几秒钟查询一次特定的TG,直到我看到该TG的状态为“健康”

到目前为止,我的任务是:

- name: Gather information about the target group attached to a particular LB
  vars:
    ansible_python_interpreter: /usr/bin/python3.6
  register: target_health
  community.aws.elb_target_group_info:
    region: "{{AWS_REGION}}"
    target_group_arns: "{{TARGET_GROUP_ARN}}"
    collect_targets_health: yes
  delegate_to: 127.0.0.1

- debug: msg="return_target_health ={{target_health}}"

- name: iterate items
  debug:
    msg: "{{ item.targets_health_description }}"
  with_items: "{{ target_health.target_groups }}"
剧本输出:

  TASK [service : debug] ****************************************************
  ok: [service.devbed-vpc.] => {
      "msg": "return_target_health ={'target_groups': [{'target_group_arn': 'arn:aws:elasticloadbalancing:us-east-1:4795703XXXXX:targetgroup/Testbed-Vee-8124-TG/b8b282d82426331c', 'target_group_name': 'Testbed-Vee-8124-TG', 'protocol': 'HTTP', 'port': 8124, 'vpc_id': 'vpc-19333d7f', 'health_check_protocol': 'HTTP', 'health_check_port': '8124', 'health_check_enabled': True, 'health_check_interval_seconds': 10, 'health_check_timeout_seconds': 5, 'healthy_threshold_count': 5, 'unhealthy_threshold_count': 2, 'health_check_path': '/health', 'matcher': {'http_code': '200'}, 'load_balancer_arns': ['arn:aws:elasticloadbalancing:us-east-1:4795703XXXXX:loadbalancer/app/Testbed-Vee-ALB/e2b8546cb7196017'], 'target_type': 'instance', 'protocol_version': 'HTTP1', 'stickiness_enabled': 'false', 'deregistration_delay_timeout_seconds': '300', 'stickiness_type': 'lb_cookie', 'stickiness_lb_cookie_duration_seconds': '86400', 'slow_start_duration_seconds': '0', 'load_balancing_algorithm_type': 'round_robin', 'tags': {'Env': 'Testbed'}, 'targets_health_description': [{'target': {'id': 'i-0b9b6e5a2775bXXXX', 'port': 8124}, 'health_check_port': '8124', 'target_health': {'state': 'healthy'}}, {'target': {'id': 'i-0feb307f8bdf6XXXX', 'port': 8124}, 'health_check_port': '8124', 'target_health': {'state': 'healthy'}}]}], 'failed': False, 'changed': False}"

  TASK [service : iterate items] ********************************************
  ok: [service.devbed-vpc.] => (item={'target_group_arn': 'arn:aws:elasticloadbalancing:us-east-1:4795703XXXXX:targetgroup/Testbed-Vee-8124-TG/b8b282d82426331c', 'target_group_name': 'Testbed-Vee-8124-TG', 'protocol': 'HTTP', 'port': 8124, 'vpc_id': 'vpc-19333d7f', 'health_check_protocol': 'HTTP', 'health_check_port': '8124', 'health_check_enabled': True, 'health_check_interval_seconds': 10, 'health_check_timeout_seconds': 5, 'healthy_threshold_count': 5, 'unhealthy_threshold_count': 2, 'health_check_path': '/health', 'matcher': {'http_code': '200'}, 'load_balancer_arns': ['arn:aws:elasticloadbalancing:us-east-1:4795703XXXXX:loadbalancer/app/Testbed-Vee-ALB/e2b8546cb7196017'], 'target_type': 'instance', 'protocol_version': 'HTTP1', 'stickiness_enabled': 'false', 'deregistration_delay_timeout_seconds': '300', 'stickiness_type': 'lb_cookie', 'stickiness_lb_cookie_duration_seconds': '86400', 'slow_start_duration_seconds': '0', 'load_balancing_algorithm_type': 'round_robin', 'tags': {'Env': 'Testbed'}, 'targets_health_description': [{'target': {'id': 'i-0b9b6e5a2775bXXXX', 'port': 8124}, 'health_check_port': '8124', 'target_health': {'state': 'healthy'}}, {'target': {'id': 'i-0feb307f8bdf6XXXX', 'port': 8124}, 'health_check_port': '8124', 'target_health': {'state': 'healthy'}}]}) => {
      "msg": [
          {
              "health_check_port": "8124",
              "target": {
                  "id": "i-0b9b6e5a2775bXXXX",
                  "port": 8124
              },
              "target_health": {
                  "state": "UNhealthy"
              }
          },
          {
              "health_check_port": "8124",
              "target": {
                  "id": "i-0feb307f8bdf6XXXX",
                  "port": 8124
              },
              "target_health": {
                  "state": "healthy"
              }
          }
      ]
  }
我希望运行此任务,直到“目标健康:状态”都健康。 我无法做到这一点,我可以将输出放到文件中,然后运行一个shell脚本,检查字符串“state”:“health”是否不止一次累积

但后来我意识到这个文件实际上是静态的,我只对它写了一次,然后我在循环中运行这个脚本,这没有任何意义

有没有一种方法可以创建此查询,直到我得到所需的正确结果,而无需将其写入文件?

这些关键字会让您感兴趣

-name:收集有关附加到特定LB的目标组的信息
变量:
ansible_python_解释器:/usr/bin/python3.6
注册:target_health
community.aws.elb_目标_群体_信息:
地区:{{AWS_地区}}”
target_group_ARN:“{{target_group_ARN}”
收集目标健康状况:是
重试次数:12次
延误:5
截止日期:>-
{{(target_health.target_groups[0]。targets_health_description | length)
==目标\u运行状况。目标\u组[0]。目标\u运行状况\u说明
|选择属性(“目标健康状态”、“均衡”、“健康”)|列表|长度}
代表:127.0.0.1
或者,如果您愿意让awscli为您暂停,您也可以使用(它不是非常ansible-y,但它可以减少ansible重试时的playbook日志输出)

-命令:>-
aws—区域{aws_区域}}等待
服务中的目标--目标组arn{{target_group_arn | quote}

我猜解析中有些错误,因为我得到:致命:[service.devbed vpc.]:失败!=>{“msg”:“条件检查{(target\u health.target\u groups{124; length)!=target\u health.target\u groups\n\124; selectattr(\'target\u health.state\',\'eq\',\'health\')列表{length}失败。错误是:计算条件时出错({(target health.target\u groups\124; length)!=target health.target u health.target groups\n\124; selectattr(\”target\u health.state\“,”eq\“,”health\”)(列表长度:“'dict object'没有属性'target\u health'”}啊,对不起,我错过了
msg:{{item.targets\u health\u description}
部分,所以
selectattr
的级别太低了。首先非常感谢,只是想告诉你我最终使用了awscli,而且它工作得很好。关于更简单的方法,它仍然失败,看起来比较中的某些东西不起作用,因为它似乎无法验证我健康的TG。失败-重试:收集有关附加到特定LB的目标组的信息(2)(还剩2次重试)。失败-重试:收集有关附加到特定LB(2)的目标组的信息(还剩1次重试)。啊,我明白了:我发明了测试,从
到:
等待true,但我用
编写了它=;抱歉,我没有TG来测试行为,所以我在文本框中编码。但我很高兴awscli方法对你有效。请考虑接受答案,让别人知道它解决了你的问题。