有问题要通过盐(状态或模块)来标记卷?

有问题要通过盐(状态或模块)来标记卷?

salt 如何标记 ec2 ebs 卷?我尝试了所有我能想到的不同方法,但都不起作用:

首先,在配置文件中标记卷:

   block_device_mappings:
     - DeviceName: /dev/sdb
       Ebs.VolumeSize: 10
       Ebs.VolumeType: standard
       tags: { 'env': 'test' }

其次,对盐状态的卷进行标记:

/dev/sdb:
  boto_ec2.volumes_tagged:
    - tag_maps:
      - filters:
        volume_ids: [ vol-0efe9141c40301871 ]
        #'attachment.device': /dev/xvdb
      - tags:
        env: test

我在运行状态时收到错误:

Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/var/tmp/.root_5c1176_salt/py2/salt/state.py", line 1745, in call
              **cdata['kwargs'])
            File "/var/tmp/.root_5c1176_salt/py2/salt/loader.py", line 1702, in wrapper
              return f(*args, **kwargs)
            File "/var/tmp/.root_5c1176_salt/py2/salt/states/boto_ec2.py", line 1209, in volumes_tagged
              r = __salt__['boto_ec2.set_volumes_tags'](**args)
            File "/var/tmp/.root_5c1176_salt/py2/salt/modules/boto_ec2.py", line 1647, in set_volumes_tags
              raise SaltInvocationError('Tag filters must be a dictionary: got {0}'.format(filters))
          SaltInvocationError: Tag filters must be a dictionary: got None`

最后,查看了模块boto_ec2.set_volumes_tags,但我就是找不到语法以及如何放置过滤器和标签。

请有人能告诉我如何用盐标记卷。谢谢,罗杰

答案1

问题解决了。如果有人有类似的问题,只需在此处发布解决方案即可:

它使用的boto_ec2.volumes_tagged状态与我的原始状态非常相似。但是,格式与普通的 salt 状态有点不寻常:

/dev/sdb:
   boto_ec2.volumes_tagged:
   # ec2_profile is defined in pillar
   - profile: ec2_profile
   - tag_maps:
     - filters:
         attachment.device: /dev/sdb
       tags:
         env: 'test'

相关内容