Reputation: 412
I am trying to run some simple playbooks to collect data from new devices that are not yet in the inventory file. This is an example playbook I use to collect data from devices that are already in the inventory file:
- name: "Demonstrate connecting to ASA"
connection: ansible.netcommon.network_cli
gather_facts: false
hosts: asa
tasks:
- name: Gather facts (asa)
cisco.asa.asa_command:
commands:
- show inventory
register: asa_vars
But what I want to achieve is that I can give any IP address of a system as variable to the playbook and the playbook executes the task on this IP which is then not in the inventory file. I am struggling how to archive that and tell ansible to use that given IP address instead of a host from inventory.
What would I use for the "host:" statement and how could I add additional parameters, for example to use a SSH bastion host, that I would usually add to an inventory file?
Upvotes: 1
Views: 3378
Reputation: 979
Maybe you're just missing the somewhat arcane syntax for specifying the inventory on the command line?
If -i is a comma separated list, it will treat it as a list of hosts rather than a file, so calling:
ansible-playbook -i 192.168.1.103, play.yml
With a trailing comma will run that play on a single, one off host.
Upvotes: 2
Reputation: 96
In your playbook:
- name: "Demonstrate connecting to ASA"
connection: ansible.netcommon.network_cli
gather_facts: false
hosts: "{{ host }}"
On the command line:
ansible-playbook myplaybook.yml --extra-vars "host=8.8.8.8"
Upvotes: 1