pyenv -v pyenv 2.2.4-1-4-g1e79a522 python -V Python 3.6.8 pip list | grep -P "ansible|boto" ansible 4.10.0 ansible-core 2.11.12 boto3 1.23.10 botocore 1.26.10 ansible-galaxy collection list | grep aws amazon.aws 5.4.0 community.aws 5.4.0
記事:
ansible-galaxy collection install community.aws:4.5.0 -f ansible-galaxy collection install amazon.aws:4.4.0 -f
ansible-galaxy collection install community.aws:1.5.0 -f ansible-galaxy collection install amazon.aws:1.5.0 -f
ansible -i hosts.ini -m ec2_metadata_facts -u centos host01
tasks: - ec2_metadata_facts:
ansible-galaxy collection install amazon.aws:4.4.0 --force
could not determine a constructor for the tag '!Ref'\n in \"<unicode string>
template_body: "{{ lookup('file','cloudformation/example.yml') | from_yaml }}"
- !Ref AwsAccountId + Ref: AwsAccountId
aws cloudformation validate-template --template-body file://cloudformation/example.yml --profile example
- name: assume role sts_assume_role: role_arn: "{{ role_arn }}" role_session_name: session1 region: "{{ region }}" profile: "{{ aws_profile }}" register: assumed_role - name: EC2 remote facts ec2_remote_facts: region: "{{ region }}" filters: instance-state-name: running register: result_ec2 changed_when: False environment: AWS_ACCESS_KEY_ID: "{{ assumed_role.sts_creds.access_key }}" AWS_SECRET_ACCESS_KEY: "{{ assumed_role.sts_creds.secret_key }}" AWS_SESSION_TOKEN: "{{ assumed_role.sts_creds.session_token }}" - name: Number of running debug: msg="{{ result_ec2.instances | count }}"
いつのバージョンから(boto3 module?)か「~/.boto」は不用になった。 assume role利用の際に邪魔になるので、「~/.boto」は作らない方が良い。
「~/.aws/credentials」が既にある場合、ansibleからその中のアクセスキー等を利用したい。
ansibleのawsモジュールには profile: オプションで boto configの値を指定でき、フォーマットはaws configと同じなのでsymlinkで良さそう
tasks: # - name: create symlink ~/.boto # file: src=~/.aws/credentials dest=~/.boto state=link - name: Delete dynamodb table dynamodb_table: profile: "{{ aws_profile }}" region: "{{ aws_region }}" name: "{{ item }}" hash_key_name: "{{ item }}" # ドキュメントでは required:no だが、実行時にエラーが出るため追加 state: absent with_items: - test