Reputation: 35
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'
Upvotes: 1
Views: 253
Reputation: 2823
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
Upvotes: 1