Calling the inventory created by first task to the second one

33 views
Skip to first unread message

Veera

unread,
Jun 14, 2023, 8:33:03 AM6/14/23
to Ansible Project
Hi,

I have a  playbook book with 2 tasks in it .
In the first tasks, I have playbooks to create a VM  and  build OS  on it  and  able to login  to the VM manually (for testing)  , and the final play creates a temporary  inventory file like below.

[dev-vm1]
mytestvm1 ansible_ssh_private_key_file: mykey.pem   ansible_ssh_user: "root" ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'

the second tasks has a bunch of plays which needs to login to the mytestvm1(using the temp inventory file)above and execute  .

I have a main.yml like this 

- name: main.play
  hosts: localhost
  tasks:
      play1:
      play2:
      play3

- hosts:  dev-vm1    
  become: true 
  gather_facts: true 
  tasks: 
       play1:
       play2:
       play2
####################################
I don't want to 
   - split them into 2 separate  playbooks
    - run with  -i inventory file 

want to pass the inventory directly to be processed by the second play ...
    






Dick Visser

unread,
Jun 14, 2023, 8:48:25 AM6/14/23
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f94670a3-f141-49ab-94ad-7c1cdd8e3fdan%40googlegroups.com.

Veera

unread,
Jun 14, 2023, 11:56:54 AM6/14/23
to Ansible Project
Thanks a lot  . I am able to overcome it .
I was missing the   indent after the add_host earlier for the second task and now I can .

Reply all
Reply to author
Forward
0 new messages