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

Configuration of access to aws services for salt-master/salt-minion

我创建了小型学习 aws 基础设施来学习 SaltStack。已经有三个 ec2 实例 运行ning。 (主人和两个仆从)。一个 minion 是 iam-role-less,一个 minion 具有使他能够访问 ec2 和 s3 操作的角色。 (角色设置纯粹用于测试目的。)

我试图发现的是如何配置 salt-master(或 salt-minion?)以便它可以访问 aws 服务。现在,我可以使用 SSH 访问第二个 minion,使用 boto3 我可以访问 ec2 和 ss3。但是,如果我使用来自 salt-master => salt-minion 的 boto_ec2 执行模块,则会发生访问错误。我知道应该使用 /etc/salt/cloud.providers/etc/salt/cloud.profiles 配置。我看到的大多数示例都期望 salt-minions 将由 salt 创建,所以我有点困惑如何使用预先存在的实例来创建它。

所以问题是:"What is the right and correct way to configure master and minions to be able to use boto_ec2 module (or any other) from salt-master and orchestrate minions. Where and how should AWS credentials (keys) be set? Which config files has to be modified/added, what commands has to be run? Instances are already up."

我找到了这个 link: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

但是没有说这个配置应该放在哪里。在 master/minion 上?哪个文件? 当我 运行 命令时:

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

没用。

请记住,云支持并未紧密集成在 saltstack 中。

如何使用预先存在的实例。 假设您有 3 个 EC2 实例。 S1 (salt master),M1 & M2 是你想部署 salt minion 的地方。

方法一:在你的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 **

重要提示:salt.state.boto_ec2 在 2015.8.8(2016 年 3 月)下不完整。所以你真的不能使用 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