dynamically set info in hosts file

41 views
Skip to first unread message

Kathy L

unread,
Nov 7, 2023, 11:15:16 AM11/7/23
to Ansible Project
I am trying to dynamically set my target host info, which I can only get to through a Bastion host.  Here is what I am doing:

  - name: Set up host
    lineinfile:
  path: "{{ inventory_file }}"
  regexp: '^ansible_ssh_common_args=-o ProxyCommand="ssh -p BASTION_port -W %h:%p -q BASTION_user@BASTION_IP"'
  line: '^ansible_ssh_common_args=-o ProxyCommand="ssh -p {{ new_ssh_port }} -W %h:%p -q {{ ansible_user }}@{{ ansible_default_ipv4.address }}"'
 
I get this error:
                   /work/hosts does not exists.

The file does exist, in that directory. I've tried chmod'ing /work/hosts to 777 which did not help. Can anyone see what I am doing wrong? Why is it not finding a file that is there?

Brian Coca

unread,
Nov 7, 2023, 11:45:58 AM11/7/23
to ansible...@googlegroups.com
You have 3 hosts involved, but you do not clarify which one you are
updating: controller, bastion or target?

I'm guessing you are using the play pointing at the target, but you
probably need to delegate the task to the controller (aka localhost).

--
----------
Brian Coca

Message has been deleted
Message has been deleted

Kathy L

unread,
Nov 7, 2023, 12:45:30 PM11/7/23
to Ansible Project
Yes. I have my ansible code on the controller. First I set up the bastion host, then I want the variables from the bastion host file copied into the hosts file.  Then I'll set up the target host.

You're right.  I can't believe I forgot that .  Thank you!
Reply all
Reply to author
Forward
0 new messages