Recently, i have learnt how to use ansible pull from youtube videos, and tried practically.
I have created terraform installation ansible playbook, that will execute with ansible pull.
By executing below playbook from anywhere, that will connect to AWS EC2 instance and it will pull terraform installation and will install terraform automatically in aws ec2 instance, and it will create a cron job as well.
Create a pre-requiste playbook as below.
main.yaml
---
- hosts: servers
remote_user: centos
become: true
become_method: sudo
gather_facts: no
tasks:
- name: Install pip on the servers
yum:
name: python-pip
state: latest
update_cache: true
become: true
- name: Install pip3 on the servers
yum:
name: python3-pip
state: latest
become: true
- name: Ensure ansible is installed on servers
pip:
name: ansible
- name: Executing ansible-pull on servers
command: ansible-pull -U https://gitlab.com/hemanth22/ansible-pull-terraform.git
inventory
[servers]
34.221.246.71
[servers:vars]
ansible_python_interpreter=/usr/bin/python
ansible_ssh_private_key_file=~/.ssh/filename.pem
ansible.cfg
[defaults]
log_path = /var/log/ansible.log
command_warnings = False
system_warnings = False
action_warnings = False
Command to install execute ansible pull.
ansible-playbook main.yml -i inventory
Top comments (0)