Reputation: 21
I do have a playbook which tooks a specific group and put all hosts of this group into a command on another host.
to be more precise. all hosts from the hosts group oldservers from my inventory file must be in the /etc/ssh.conf on one or multiple clients.
the task looks like...
---
- name: echo Old Servers
debug:
var: groups["oldservers"]
- name: create ssh_conf_for_old_server
blockinfile:
path: /etc/ssh/ssh_config
backup: True
block: |
Host {{ groups["oldservers"]|join(' ') }}
user admin
KexAlgorithms +diffie-hellman-group1-sha1
HostKeyAlgorithms +ssh-dss
Ciphers +aes128-cbc
this should be executed on a client which is not member of the group servers.
hosts file (inventory):
[clients]
192.168.200.1
192.168.200.2
[oldservers]
192.168.201.1
192.168.201.2
My execution line is ansible-playbook -i 192.168.200.1, -u ansible ./createServerList.yml
I guess I should do it a bit different. Dont I ?
The result should be ... at first output all the oldservers (debug) than write a block with these old server into the /etc/ssh/ssh_config
Upvotes: 1
Views: 567
Reputation: 361
For command ansible-playbook -i 192.168.200.1 -u ansible ./createServerList.yml
, you are passing the ip address directly as inventory. Because of this Ansible is unaware of the inventory file where host groups are defined. So can you try running this instead ansible-playbook -i <path_to_inventory_file> -u ansible ./createServerList.yml
And then if you have to restrict playbook running only certain hosts or group, do
ansible-playbook -i <path_to_inventory_file> -u ansible ./createServerList.yml --limit "192.168.200.1,192.168.200.2"
OR
ansible-playbook -i <path_to_inventory_file> -u ansible ./createServerList.yml --limit clients
Upvotes: 1