DEV Community

Hemanth B
Hemanth B

Posted on

1

How to install terraform using ansible pull

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

Enter fullscreen mode Exit fullscreen mode

inventory

[servers]
34.221.246.71
[servers:vars]
ansible_python_interpreter=/usr/bin/python
ansible_ssh_private_key_file=~/.ssh/filename.pem
Enter fullscreen mode Exit fullscreen mode

ansible.cfg

[defaults]
log_path = /var/log/ansible.log
command_warnings = False
system_warnings = False
action_warnings = False
Enter fullscreen mode Exit fullscreen mode

Command to install execute ansible pull.

ansible-playbook main.yml -i inventory

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay