I am trying to assign to hostname to AWS EC2 instances from Ansible and It was provisioned from Terraform and Jenkins. I have extracted the hostname output from Terraform and stored as a input.txt file, I want to call the input.txt file to pass the hostname values.
I tried the below playbook but result is not expected.
The expected output should be
host1: test1host2: test2
---
- hosts: main
become: true
tasks:
- name: Configure hostname
win_hostname:
name: "{{ item }}"
register: result
with_items: "{{lookup( 'file', 'input.txt').split('\n') }}"
Which gives
TASK [Configure hostname] ****************************************************
changed: [13.57.245.193] => (item=test1)
changed: [54.193.219.112] => (item=test1)
changed: [13.57.245.193] => (item=test2)
changed: [54.193.219.112] => (item=test2)
input.txt:
test1
test2