Skip to content

Instantly share code, notes, and snippets.

View nleiva's full-sized avatar
☠️
Working from somewhere

Nicolas Leiva nleiva

☠️
Working from somewhere
View GitHub Profile
- name: Copy file Lab folder with owner and permissions
ansible.builtin.copy:
src: "{{ playbook_dir }}/lab"
dest: "/home/{{ ansible_user }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0755'
- name: Ensure group "docker" exists
ansible.builtin.group:
name: docker
state: present
- name: Append user {{ ansible_user }} to the group 'docker'
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: docker
append: yes
- name: Install Docker
ansible.builtin.package:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
- name: Ensure Docker is started and enabled at boot
ansible.builtin.service:
- name: Download Go
ansible.builtin.get_url:
url: "{{ go_download_url }}"
dest: "/tmp/go{{ go_version }}.tar.gz"
mode: '0644'
- name: Unarchive Go
ansible.builtin.unarchive:
src: "/tmp/go{{ go_version }}.tar.gz"
dest: "/usr/local"
- name: Install base packages
ansible.builtin.package:
name: "{{ common_software }}"
state: present
python_libraries:
- ipaddress
common_software:
- git
- wget
- tree
- tar
- python3-pip
- ansible
- name: Setup hostname
ansible.builtin.hostname:
name: "{{ hostvars[inventory_hostname] }}"
- name: Add instance(s) to my_instances group
ansible.builtin.add_host:
name: "{{ item.tags.Name }}"
ansible_host: "{{ item.public_ip_address }}"
ansible_user: "{{ ec2_username }}"
private_ip: "{{ item.private_ip_address }}"
instance_name: "{{ ec2_resource_prefix }}"
ansible_ssh_private_key_file: "{{ playbook_dir }}/{{ ec2_resource_prefix }}-private.pem"
instance_ssh: "{{ ssh_info }}"
groups:
- name: Wait until we can SSH to the instance
ansible.builtin.wait_for:
host: "{{ ec2.instances[0].public_ip_address }}"
port: 22
state: started