with_items -- only part of the group in my inventory

Hi,

I have a task based on shell command that need to run on local computer. As part of the command I need to add the IP address of part of the groups I have in my inventory file

Inventory file :

[server1]

130.1.1.1

130.1.1.2

[server2]

130.1.1.3

130.1.1.4

[server3]

130.1.1.5

130.1.1.6

I need to run the following command from local computer on the Ips that are part of the Server 2 + 3 groups

Ssh-copy-id user@IP ; IP should be 130.1.1.3 , 130.1.1.4 , 130.1.1.5 , 130.1.1.6

Playbook

  • hosts: localhost
    gather_facts: no
    become: yes
    tasks:
  • name: Generate ssh key for root user
    shell: "ssh-copy-id user@{{ item }}
    run_once: True
    with_items:
  • server2 group
  • server3 group

Thank you

If you have an inventory and the SSH key is on localhost, perhaps it’s easier to just run your playbook against all and delegate to localhost (rather than only running it against localhost)?

For example: