首页 文章

配置访问salt-master / salt-minion的aws服务

提问于
浏览
3

我已经创建了小型的研究aws基础设施来学习SaltStack . 已经有三个ec2实例正在运行 . (师父和两个奴才) . 一个小兵是iam-role-less,一个小兵有角色,使他能够访问ec2和s3动作 . (角色设置纯粹用于测试目的 . )

我想要发现的是如何配置salt-master(或salt-minion?) so it has access to aws services . 现在,我可以使用SSH访问第二个小兵并使用boto3我可以访问ec2和ss3 . 但是如果我使用salt-master => salt-minion中的boto_ec2执行模块,则会发生访问错误 . 我知道应该使用/etc/salt/cloud.providers和/etc/salt/cloud.profiles配置 . 我看到的大多数例子都预计salt-minions将由salt创建,所以我对如何使用预先存在的实例进行操作感到困惑 .

所以问题是:“配置master和minions以正确使用来自salt-master和orchestrate minions的boto_ec2模块(或任何其他模块)的正确方法是什么 . 在哪里以及如何设置AWS凭证(密钥)?必须修改/添加哪些配置文件,必须运行哪些命令?实例已经启动 . “

我找到了这个链接:https://salt-cloud.readthedocs.org/en/latest/topics/aws.html但是有地方,它说:

"The following settings are always required for EC2:"

# Set the EC2 login data
my-ec2-config:
  id: HJGRYCILJLKJYG
  key: 'kdjgfsgm;woormgl/aserigjksjdhasdfgn'
  keyname: test
  securitygroup: quick-start
  private_key: /root/test.pem
  provider: ec2

但是没有说这个配置应该在哪里 . 在主人/奴才?哪个文件?当我运行命令时:

# salt '*142*' boto_ec2.exists Master
: 'boto_ec2' __virtual__ returned False
ERROR: Minions returned with non-zero exit code

它不起作用 .

1 回答

  • 2

    请记住, Cloud 支持没有紧密集成在saltstack中 .

    How to do it with pre-existing instances. 假设您有3个EC2实例 . S1(盐主),M1和M2是你想要部署盐奴隶的地方 .

    方法1:在salt master中安装salt-cloud,使用saltify方法

    # filename : /etc/cloud.providers.d/sality-driver.conf
    aws-saltify:
      minion:
        master: <ip_address_of_your_salt_master> 
      driver: saltify    
    
    # filename : /etc/cloud.profiles.d/salt-minion.conf
    minion1: 
      ssh_host: <M1-ip>
      ssh_username: <your_aws_instance_user_name>
      key_filename: "<full private_key_file path use to connect to minion>"
      provider: aws-saltify
    
    minion2: 
      ssh_host: <M2-ip>
      ssh_username: <your_aws_instance_user_name>
      key_filename: "<full private_key_file path use to connect to minion2>"
      provider: aws-saltify
    
    # run the command to saltify those host
    
    sudo salt-cloud saltify -p minion1 <minion1-host-name>
    sudo salt-cloud saltify -p minion2 <minion2-host-name>
    

    手指交叉如果有效 .

    **方法2:使用salt-ssh **

    重要说明:在2015 . 8 . 8(2016年3月)下,salt.state.boto_ec2未完成 . 所以你真的不能使用boto_ec2将salt-minion部署到那些机器中,也许你可以尝试boto_lc或等待新功能 .

    #Create a folder just for salt-ssh deployment
    mkdir ~/saltme
    
    # master file for salt-ssh  ~/saltme/master 
    file_roots:
      base:
      # Replace the "~" with you $HOME full path.  
        - ~/saltme/master
    
    #create a roster file ~/saltme/minion-roster
    my-bare-M1: 
      host: <to-be-minion-1-host-ip-address>
      user: <ami-default >
      sudo: True
    
    my-bare-M2: 
      host: <to-be-minion-2-host-ip-address>
      user: <ami-default >
      sudo: True
    
    # create your top file   ~/saltme/top.sls
    base:
      '*':
        - saltify-minion
    
    # create the state file ~/saltme/saltify-minion.sls
    salt-minion:
      pkg.installed
    
    
    # Now , inside the ~/saltme , run this against each to-be-minion-ec2
    salt-ssh --roster-file roster --config-dir $HOME/saltme  -i --priv saltminion-1.pem  'my-bare-M1'  state.highsatte
    
    salt-ssh --roster-file roster --config-dir $HOME/saltme  -i --priv saltminion-1.pem  'my-bare-M2'  state.highsatte
    #Now accept the salt-minion key 
    sudo salt-key -A
    

相关问题