1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Improve examples and remove shell (#19208)

This commit is contained in:
Fabio Alessandro Locati 2017-01-19 17:15:24 +00:00 committed by John R Barker
parent 7a275f61de
commit b2acba0d16

View file

@ -53,53 +53,49 @@ extends_documentation_fragment:
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Basic example of adding tag(s) - name: Ensure tags are present on a resource
tasks: ec2_tag:
- name: tag a resource region: eu-west-1
ec2_tag: resource: vol-XXXXXX
region: eu-west-1
resource: vol-XXXXXX
state: present state: present
tags: tags:
Name: ubervol Name: ubervol
env: prod env: prod
# Playbook example of adding tags to volumes on an instance - name: Ensure one dbserver is running
tasks: ec2:
- name: launch an instance
ec2:
count_tags: count_tags:
Name: dbserver Name: dbserver
Env: production Env: production
exact_count: 1 exact_count: 1
group: "{{ security_group }}" group: '{{ security_group }}'
keypair: "{{ keypair }}" keypair: '{{ keypair }}'
image: "{{ image_id }}" image: '{{ image_id }}'
instance_tags: instance_tags:
Name: dbserver Name: dbserver
Env: production Env: production
instance_type: "{{ instance_type }}" instance_type: '{{ instance_type }}'
region: eu-west-1 region: eu-west-1
volumes: volumes:
- device_name: /dev/xvdb - device_name: /dev/xvdb
device_type: standard device_type: standard
volume_size: 10 volume_size: 10
delete_on_termination: true delete_on_termination: True
wait: true wait: True
register: ec2 register: ec2
- name: list the volumes for the instance - name: Retrieve all volumes for a queried instance
ec2_vol: ec2_vol:
instance: "{{ item.id }}" instance: '{{ item.id }}'
region: eu-west-1 region: eu-west-1
state: list state: list
with_items: "{{ ec2.tagged_instances }}" with_items: '{{ ec2.tagged_instances }}'
register: ec2_vol register: ec2_vol
- name: tag the volumes - name: Ensure all volumes are tagged
ec2_tag: ec2_tag:
region: eu-west-1 region: eu-west-1
resource: "{{ item.id }}" resource: '{{ item.id }}'
state: present state: present
tags: tags:
Name: dbserver Name: dbserver
@ -108,21 +104,19 @@ tasks:
- ec2_vol.results - ec2_vol.results
- volumes - volumes
# Playbook example of listing tags on an instance - name: Get EC2 facts
tasks:
- name: get ec2 facts
action: ec2_facts action: ec2_facts
- name: list tags on an instance - name: Retrieve all tags on an instance
ec2_tag: ec2_tag:
region: "{{ ansible_ec2_placement_region }}" region: '{{ ansible_ec2_placement_region }}'
resource: "{{ ansible_ec2_instance_id }}" resource: '{{ ansible_ec2_instance_id }}'
state: list state: list
register: ec2_tags register: ec2_tags
- name: list tags, such as Name, env if exist - name: List tags, such as Name and env
shell: echo {{ ec2_tags.tags.Name }} {{ ec2_tags.tags.env }} debug:
msg: '{{ ec2_tags.tags.Name }} {{ ec2_tags.tags.env }}'
''' '''