AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-554459

housemd's questions

Martin Hope
housemd
Asked: 2021-06-17 14:41:59 +0800 CST

Ansible 打印调试消息结果变量

  • 1

我有一个简单的任务,我无法克服。

我有一个返回 AWS EC2 实例配置的剧本。我只需要打印(显示)private_ip_address。

这是我的剧本

---
- hosts: local
  connection: local
  gather_facts: false
  become: yes
  become_method: enable

  tasks:

  - name: gather-info-ec2
    community.aws.ec2_instance_info:
      instance_ids:
        - i-XXXXXAAAAAA

    register: ec2

  - debug: msg="{{ ec2.instances.network_interfaces.private_ip_address }}"

当我像这样运行它时,我收到以下错误。

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'network_interfaces'\n\nThe error appears to be in '/etc/ansible/playbooks/AWSLinuxMigration/gather_ec2_info.yaml': line 16, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - debug: msg=\"{{ ec2.instances.network_interfaces.private_ip_address }}\"\n    ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}

当我在没有 DEBUG 部分并使用-vvv的情况下执行它时,它会显示以下结果。如何提取并打印此地址?我把它缩短了一点,但你明白了

ok: [localhost] => {
    "msg": {
        "changed": false,
        "failed": false,
        "instances": [
            {
                "ami_launch_index": 0,
                "architecture": "x86_64",
                "block_device_mappings": [
                    {
                        "device_name": "/dev/xvda",
                        "ebs": {
                            "attach_time": "2020-04-15T16:11:19+00:00",
                            "delete_on_termination": true,
                            "status": "attached",
                            "volume_id": "xxxxxx"
                        }
                    }
                ],
                "capacity_reservation_specification": {
                    "capacity_reservation_preference": "open"
                },
                "client_token": "",
                "cpu_options": {
                    "core_count": 1,
                    "threads_per_core": 2
                },
                "ebs_optimized": true,
                "ena_support": true,
                "enclave_options": {
                    "enabled": false
                },
                "hibernation_options": {
                    "configured": false
                },
                "hypervisor": "xen",
                "iam_instance_profile": {
                    "arn": "xxxxxx",
                    "id": "xxxxxx"
                },
                "image_id": "xxxxx",
                "instance_id": "xxxxx",
                "instance_type": "t3.medium",
                "key_name": "xxxxx",
                "launch_time": "2021-04-21T00:01:25+00:00",
                "metadata_options": {
                    "http_endpoint": "enabled",
                    "http_put_response_hop_limit": 1,
                    "http_tokens": "optional",
                    "state": "applied"
                },
                "monitoring": {
                    "state": "disabled"
                },
                "network_interfaces": [
                    {
                        "association": {
                            "ip_owner_id": "xxxx",
                            "public_dns_name": "xxxxx",
                            "public_ip": "xxxx"
                        },
                        "attachment": {
                            "attach_time": "2020-04-15T16:11:18+00:00",
                            "attachment_id": "xxxxx",
                            "delete_on_termination": true,
                            "device_index": 0,
                            "network_card_index": 0,
                            "status": "attached"
                        },
                        "description": "Primary network interface",
                        "groups": [
                            {
                                "group_id": "xxxxx",
                                "group_name": "xxxxx"
                            }
                        ],
                        "interface_type": "interface",
                        "ipv6_addresses": [],
                        "mac_address": "xxxxx",
                        "network_interface_id": "xxxx",
                        "owner_id": "xxxxx",
                        "private_dns_name": "ip-10-0-1-161.ec2.internal",
                        "private_ip_address": "10.0.1.161",
                        "private_ip_addresses": [
                            {
                                "association": {
                                    "ip_owner_id": "xxxxx",
                                    "public_dns_name": "xxxx.compute-1.amazonaws.com",
                                    "public_ip": "2.2.2.2"
                                },
                                "primary": true,
                                "private_dns_name": "ip-333333.ec2.internal",
                                "private_ip_address": "1.1.1.1."
                            }
                        ],
                        "source_dest_check": true,
                        "status": "in-use"

                    }
                ]
        ]
    }
}
debug variables ansible ansible-playbook
  • 1 个回答
  • 2724 Views
Martin Hope
housemd
Asked: 2020-01-06 10:30:07 +0800 CST

Apache HTTP 到 HTTPS 代理重定向多个地址

  • 0

我需要你的帮助。

我在 Linux 机器上运行了 2 个版本的应用程序。版本 1 在 localhost 端口 5000 上运行,版本 2 在 localhost 端口 5001 上运行。

我需要用户能够根据他们使用的 URL 访问任一应用程序版本。

我现有的 Apache httpd.conf 如下:

当用户键入 http:/my.company.com 时,它会将他们重定向到 HTTPS 端口 443,端口 443 会重定向到 localhost 5000。这很有效。

<VirtualHost *:80>                                                                                                                                          
ServerName my.company.com                                                                                                                  
Redirect / https://my.company.com/                                                                                                                 
</VirtualHost>                                                                                                                                                                  

<VirtualHost *:443>                                                                                                                                        
ServerName my.company.com/                                                                                                                 
TimeOut 600                                                                                                                                                     
ProxyPreserveHost On                                                                                                                                            
ProxyRequests Off                                                                                                                                            
ProxyPass / http://localhost:5000/                                                                                                                           
ProxyPassReverse / http://localhost:5000/                                                                                                                
SSLEngine on                                                                                                                                                     
SSLOptions +StrictRequire                                                                                                                                
SSLCertificateFile /etc/pki/tls/certs/my.company.crt                                                                                                               
SSLCertificateKeyFile /etc/pki/tls/private/my.company.key                                                                                     
</VirtualHost>  

现在我需要在用户键入http://my.company.com:15000时将其重定向到某个 HTTPS 端口,该端口重定向到我的应用程序正在侦听的 localhost 5001。

如果有其他方法可以做到这一点,比如使用不同的域名,比如 my-v2.company.com,它也可以。我可以创建一个新的 DNS 条目。这个想法是,当用户使用不同的端口或不同的域时,它应该将他们重定向到不同的应用程序端口。

我尝试在这里搜索并尝试了多种设置,但无法使其以这种方式工作。

apache-2.4
  • 1 个回答
  • 1258 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve