【问题标题】:How to run Ansible play-book command from remote server如何从远程服务器运行 Ansible play-book 命令
【发布时间】:2019-05-19 18:18:06
【问题描述】:

我需要根据要求安装和配置所有新系统,从 aws 中的自动缩放开始,例如,如果它是一个应用服务器安装 nodejs,并使用相应的 git 代码与 Ansible 一起部署。

Ansible 如何识别一个新系统并需要进行所有配置。

【问题讨论】:

    标签: amazon-ec2 ansible autoscaling


    【解决方案1】:

    这里是 ansible 文档中关于如何使用 Ansible 处理自动缩放的指南:https://docs.ansible.com/ansible/latest/scenario_guides/guide_aws.html#autoscaling-with-ansible-pull

    这个方法的问题是,您需要在启动时提供整个配置过程。这需要很长时间并且容易出错。

    一种常见的解决方案是使用您的服务所需的所有基础架构构建一个自定义 AMI,并且仅将您当前的代码部署到此机器上。

    构建自定义 AMI 的好工具是 Packer。 AWS 指南可在此处获得。 https://www.packer.io/docs/builders/amazon.html

    【讨论】:

    • 我们可以使用常见的 AMI,但是我们如何进行部署,它应该是自动的,它的自动缩放系统,我已经创建了一个脚本文件并添加到 aws 用户数据,脚本将采用实例 ip 和在清单文件中添加,将该清单文件复制到 ansible 服务器,然后再次登录到 ansible 服务器并使用此清单文件运行剧本。但我不知道为什么,它甚至连单行都没有运行。并且错误得到2019-02-27 06:07:29,130 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'b'sudo sh /home/ubuntu/sta'...'
    • ## 启动脚本#!/bin/bash ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/' > ip.txt a=cat ip.txt` && sed -i "2 i\\$a" inventory.cfg scp -C -i ~/.ssh/id_rsa.pem 库存。 cfg ubuntu@172.31.31.215:/etc/ansible/inventory/ ##将库存文件复制到ansible ssh -i ~/.ssh/id_rsa.pem ubuntu@172.31.31.215 'ansible-playbook -i /etc/ansible/inventory/库存.cfg /etc/ansible/air-hub.yml -b' `
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 2021-01-03
    相关资源
    最近更新 更多