1

So i'm running an ansible playbook, which creates a server (using terraform) and gives saves the ip-address of the server into a variable. i'd like to execute another task on the given ip-address. How do i declare the new host?

I've tried:

- hosts: "{{ remotehost }}" tasks: - name: test lineinfile: path: /etc/environment line: test1234

I run the playbook with: ansible-playbook variable.yaml --extra-vars='playbook=ip-address'

Paasi
  • 33
  • 1
  • 5
  • The solution on https://stackoverflow.com/questions/51519735/can-ansible-variables-be-used-to-declare-hosts-in-a-playbook doesn't work.. – Paasi Feb 13 '20 at 14:58

1 Answers1

1

If you just want to execute a single task you can use delegate_to

For example:

tasks:
  - name: another host execute
    command: ls -ltr
    delegate_to: "{{ remotehost }}"

The server should have the ssh connection working with the new hosts

error404
  • 2,684
  • 2
  • 13
  • 21