Seems to ignore value for `hosts` variable and creates users on the local host
carygravel opened this issue · comments
I had expected the following playbook to prepare the remotes listed in the hosts
variable, but instead it seemed all to be carried out on the host on which the playbook was run.
- name: Set up remotes to allow rsnapshot on my_rsnapshot_server to pull
hosts: host1 host2
become: true
roles:
- role: yannik.rsnapshot-remote-host
rsnapshot_backup_host: my_rsnapshot_server
Is my expectation unreasonable? Or are there technical reasons why that can't work? Or have I misunderstood how it all works?
Can you put your code in a code block? Right now it's hard to read.
Sorry. Yes. Don't know what I was thinking.
Thank you.
I had expected the following playbook to prepare the remotes listed in the hosts variable, but instead it seemed all to be carried out on the host on which the playbook was run.
Can you post the output of ansible-playbook
and describe in more detail what exactly you are seeing that seems incorrect?
Sure here's the output, executed on host1. Everything happens on host1
, even though I specified host1
and host2
in the hosts
variable. Indeed, even if I only list host2
in the hosts
variable, if I execute it on host1
, all the action still happens on host1
.
PLAY [Set up remotes to allow rsnapshot on my_rsnapshot_server to pull] ********************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Ensure ssh server package is installed] *************************************************************************************************************************
ok: [host1] => (item=openssh-server)
TASK [yannik.rsnapshot-remote-host : Ensure rsync and sudo are installed] ****************************************************************************************************************************
ok: [host1] => (item=rsync)
ok: [host1] => (item=sudo)
TASK [yannik.rsnapshot-remote-host : Ensure ssh server service is enabled] ***************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Ensure backupro user exists] ************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Ensure home folder has correct permissions (0700)] **************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Create ssh directory] *******************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Fetch ssh key from backup pulling host] *************************************************************************************************************************
ok: [host1 -> my_rsnapshot_server]
TASK [yannik.rsnapshot-remote-host : Create ssh key for testing] *************************************************************************************************************************************
skipping: [host1]
TASK [yannik.rsnapshot-remote-host : Add key to authorized_keys] *************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Fetch ssh hostkey] **********************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Install hostkey on backup pulling host] *************************************************************************************************************************
[DEPRECATION WARNING]: Use 'ansible.utils.ipaddr' module instead. This feature will be removed from ansible.netcommon in a release after 2024-01-01. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
changed: [host1 -> my_rsnapshot_server] => (item=my_rsnapshot_server)
TASK [yannik.rsnapshot-remote-host : Remove temporary files from local host] *************************************************************************************************************************
ok: [host1 -> localhost] => (item=tmp-rsnapshot-host-key)
ok: [host1 -> localhost] => (item=tmp-rsnapshot-ssh-key)
TASK [yannik.rsnapshot-remote-host : Install rrsync] *************************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Make sure /var/log/rrsync.log is created with correct permissions] **********************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Add sudoers config] *********************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Install ssh wrapper script] *************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Install backup-scripts] *****************************************************************************************************************************************
ok: [host1]
TASK [yannik.rsnapshot-remote-host : Install custom backup-scripts] **********************************************************************************************************************************
skipping: [host1]
TASK [yannik.rsnapshot-remote-host : Print ssh server warning message] *******************************************************************************************************************************
skipping: [host1]
PLAY RECAP *******************************************************************************************************************************************************************************************
host1 : ok=17 changed=1 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
I believe the problem is that you are using incorrect syntax for hosts
.
Try changing hosts: host1 host2
to hosts: host1,host2
The more elegant way would be to use a group, of course.
Thank you. Yes, the documentation says that a comma or a colon should be used as a separator. Unfortunately, it didn't make any difference.
Hm, that seems very odd. I'd suggest you double check this and post your hosts-file, ansible-playbook
invocation and output again.
Currently, I see the following snippet in tasks.yml:
- name: Ensure rsync and sudo are installed
package: name={{ item }} state=present
with_items:
- rsync
- sudo
when: rsnapshot_install_packages
Won't this be executed by default on the machine on which the play was run?
Wouldn't it make more sense to execute tasks like these on all the machines in the hosts
variable, i.e. additionally using lines like:
loop: '{{ ansible_play_hosts_all }}'
delegate_to: "{{ item }}"
Is this the reason why I am not seeing the behaviour I expect?
Tasks like this are always run on the hosts defined in hosts
in your playbook, there is no need to use delegate_to
.
OK. Thanks for the help. I found the mistake in my inventory file.