| --- |
| - hosts: '{{ hosts }}' |
| |
| vars: |
| ansible_config: ~/.ansible |
| |
| tasks: |
| - name: Install system packages |
| become: yes |
| yum: |
| name: '{{ item }}' |
| state: present |
| with_items: |
| - elasticache-auto-discovery |
| when: ansible_os_family | lower == 'redhat' |
| |
| |
| - name: Create a template .boto config file |
| template: |
| src: resources/boto.j2 |
| dest: ~/.boto |
| mode: 0644 |
| when: aws_access_key is defined and aws_secret_key is defined and aws_region is defined |
| |
| - name: Create a template ec2.ini config file |
| copy: |
| src: resources/ec2.ini |
| dest: '{{ ansible_config }}/ec2.ini' |
| mode: 0644 |
| |
| - name: Update EC2_INI_PATH |
| lineinfile: |
| backup: yes |
| dest: ~/.bashrc |
| state: present |
| line: 'export EC2_INI_PATH={{ ansible_config }}/ec2.ini' |
| when: aws_access_key is defined and aws_secret_key is defined and aws_region is defined |
| |
| - name: Copy ec2.py script |
| copy: |
| src: resources/ec2.py |
| dest: '{{ ansible_config }}/ec2.py' |
| |
| - name: Update .bashrc with aws_access_key |
| lineinfile: |
| backup: yes |
| dest: ~/.bashrc |
| state: present |
| line: 'export AWS_SECRET_ACCESS_KEY={{ aws_access_key }}' |
| when: aws_access_key is defined and update_env is defined and update_env |
| |
| - name: Update .bashrc with aws_secret_key |
| lineinfile: |
| backup: yes |
| dest: ~/.bashrc |
| state: present |
| line: 'export AWS_ACCESS_KEY_ID={{ aws_secret_key }}' |
| when: aws_secret_key is defined and update_env is defined and update_env |
| |