1

How salt can tag ec2 ebs volumes? I have tried all different ways I could think of, but non of them working:

First, tag volumes in profile:

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

Secondly, tag volumes in salt state:

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

I got the error when the state was run:

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`

Finally, have looked the module boto_ec2.set_volumes_tags, but I just could not find out the syntax and how to put the filters and tags.

Please anyone could show me how to tag volumes by salt. Thanks, Roger

Tim
  • 30,383
  • 6
  • 47
  • 77
Roger
  • 91
  • 1
  • 3
  • 8

1 Answers1

2

Problem solved. Just post the solution here in case anyone have the similar question:

It is using boto_ec2.volumes_tagged state pretty similar with my original state. However, the format is a bit unusual than normal salt states:

/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'
Roald Nefs
  • 426
  • 5
  • 13
Roger
  • 91
  • 1
  • 3
  • 8