After testing wit some hosts i tried to use some more (24) and the playbook runs, but the last task gets skipped:
PLAY [Copy all txt files from localhost to 192.168.151.241] ********************
skipping: no hosts matched
---
- name: Do password work
hosts: all
become: yes
vars:
ntp_server: "time.gruen.net"
timezone: "Europe/Berlin"
usr_2_edit: gsa
tasks:
- name: Get the hostname
ansible.builtin.command: "hostname"
register: hostname_result
- name: Set csv_pth variable based on hostname
set_fact:
csv_pth: "/tmp/{{ hostname_result.stdout }}_bw_pw_add_gsa_test.csv"
- name: Ensure the CSV file exists
ansible.builtin.file:
path: "{{ csv_pth }}"
state: touch
- name: Add header to CSV file if missing
ansible.builtin.lineinfile:
path: "{{ csv_pth }}"
line: 'folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp'
insertbefore: BOF
state: present
- name: Get the current date in HH:MM_DD.mm.yyyy format
ansible.builtin.command: "date +'%H:%M_%d.%m.%Y'"
register: date_result
- name: Generate a random password
ansible.builtin.command: "openssl rand -base64 12"
register: password_result
- name: Get the primary IP address
ansible.builtin.set_fact:
ip_address: "{{ ansible_default_ipv4.address }}"
- name: Update or create user with the specified username and password
ansible.builtin.user:
name: "{{ usr_2_edit }}"
password: "{{ password_result.stdout | password_hash('sha512') }}"
state: present
- name: Append data to CSV file
ansible.builtin.lineinfile:
path: "{{ csv_pth }}"
line: ",,login,{{ hostname_result.stdout }},{{ date_result.stdout }},,0,{{ ip_address }},{{ usr_2_edit }},{{ password_result.stdout }},"
insertafter: EOF
- name: Install the python3-pexpect module
ansible.builtin.package:
name: python3-pexpect
state: present
- name: Test the user password
ansible.builtin.expect:
command: "su - {{ usr_2_edit }}"
responses:
"Password:": "{{ password_result.stdout }}"
register: password_test
failed_when: "'authentication failure' in password_test.stdout"
- name: Print password test result
ansible.builtin.debug:
msg: "Password change for user {{ usr_2_edit }} was successful."
when: password_test.rc == 0
- name: Copy the file to the Ansible controller
ansible.builtin.fetch:
src: "{{ csv_pth }}"
dest: /tmp/
flat: yes
- name: Show contents of /tmp directory on the Ansible controller
hosts: localhost
tasks:
- name: List only the relevant test files in /tmp directory on localhost
ansible.builtin.shell: "ls -l /tmp | grep '_bw_pw_add_gsa_test.csv'"
register: tmp_contents_local
- name: Display filtered /tmp contents on localhost
ansible.builtin.debug:
msg: "{{ tmp_contents_local.stdout }}"
- name: Get a list of all txt files on the controller
ansible.builtin.find:
paths: /tmp/
patterns: "*_bw_pw_add_gsa_test.csv"
register: txt_files
- name: Copy all txt files from localhost to 192.168.151.241
hosts: 192.168.151.241
tasks:
- name: Copy all txt files to the remote host
ansible.builtin.copy:
src: "{{ item.path }}"
dest: /opt/awx/passwords/new
remote_src: no
force: yes
loop: "{{ hostvars['localhost']['txt_files']['files'] }}"
the test outpu show that for all the hosts where successfully the csv files generated.
I dont get why with less hosts everything is fine
TASK [Display filtered /tmp contents on localhost] *****************************
task path: /runner/project/functions/user/change_gsa_pw_random_BW_API/changepw_ansiblcntrll_gsa_randpw_functionabel.yaml:87
ok: [localhost] => {
"msg": "-rw-r--r-- 1 1000 root 342 Aug 22 14:41 Limesurvey-118_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 MySQL-10_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 MySQL-96_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 330 Aug 22 14:41 MySQL8-238_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 Nagios40_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 342 Aug 22 14:41 RADIUS-NAC-100_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 330 Aug 22 14:41 Syslog-186_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 330 Aug 22 14:41 ansiblesrv_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 apiwork_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 771 Aug 22 14:41 awxgsatransfersrv_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 172 Aug 22 14:41 backup-2_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 300 Aug 22 14:41 chat_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 339 Aug 22 14:41 devtest-151-30_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 312 Aug 22 14:41 dms2_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 330 Aug 22 14:41 docker-196_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 339 Aug 22 14:41 giftgruen-245_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 318 Aug 22 14:41 git-246_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 624 Aug 22 14:41 glpi-172_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 333 Aug 22 14:41 jenkins-240_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 mysql-42_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 321 Aug 22 14:41 mysql-57_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 354 Aug 22 14:41 nomin-websrv-19-201_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 345 Aug 22 14:41 nominatim-19-200_bw_pw_add_gsa_test.csv\\n-rw-r--r-- 1 1000 root 675 Aug 22 14:41 web-89_bw_pw_add_gsa_test.csv"
}
TASK [Get a list of all txt files on the controller] ***************************
task path: /runner/project/functions/user/change_gsa_pw_random_BW_API/changepw_ansiblcntrll_gsa_randpw_functionabel.yaml:91
ok: [localhost] => {"changed": false, "examined": 29, "files": [{"atime": 1724337699.450172, "ctime": 1724337699.450172, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986653, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.450172, "nlink": 1, "path": "/tmp/docker-196_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 330, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.8462186, "ctime": 1724337700.8462186, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986665, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.8462186, "nlink": 1, "path": "/tmp/awxgsatransfersrv_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 771, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337699.3301678, "ctime": 1724337699.3301678, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986651, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.3301678, "nlink": 1, "path": "/tmp/MySQL-96_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337701.5622425, "ctime": 1724337701.5622425, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986672, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337701.5622425, "nlink": 1, "path": "/tmp/giftgruen-245_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 339, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337698.142128, "ctime": 1724337698.142128, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986640, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337698.142128, "nlink": 1, "path": "/tmp/mysql-42_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337699.5501752, "ctime": 1724337699.5501752, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986654, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.5501752, "nlink": 1, "path": "/tmp/jenkins-240_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 333, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337697.7981164, "ctime": 1724337697.7981164, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986635, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337697.7981164, "nlink": 1, "path": "/tmp/apiwork_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.4782064, "ctime": 1724337700.4782064, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986663, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.4782064, "nlink": 1, "path": "/tmp/Syslog-186_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 330, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.9862232, "ctime": 1724337700.9862232, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986666, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.9862232, "nlink": 1, "path": "/tmp/nomin-websrv-19-201_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 354, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.7502153, "ctime": 1724337700.7502153, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986662, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.7502153, "nlink": 1, "path": "/tmp/glpi-172_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 624, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337701.1382284, "ctime": 1724337701.1382284, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986669, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337701.1382284, "nlink": 1, "path": "/tmp/nominatim-19-200_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 345, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337697.7861161, "ctime": 1724337697.7861161, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986625, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337697.7861161, "nlink": 1, "path": "/tmp/MySQL-10_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.950222, "ctime": 1724337700.950222, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986667, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.950222, "nlink": 1, "path": "/tmp/Nagios40_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337701.48224, "ctime": 1724337701.48224, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986671, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337701.48224, "nlink": 1, "path": "/tmp/dms2_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 312, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.2821996, "ctime": 1724337700.2821996, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986660, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.2821996, "nlink": 1, "path": "/tmp/web-89_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 675, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337697.726114, "ctime": 1724337697.722114, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986634, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337697.722114, "nlink": 1, "path": "/tmp/ansiblesrv_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 330, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337701.3182344, "ctime": 1724337701.3182344, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986668, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337701.3182344, "nlink": 1, "path": "/tmp/chat_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 300, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.0021904, "ctime": 1724337699.9981902, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986659, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.9981902, "nlink": 1, "path": "/tmp/git-246_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 318, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.8462186, "ctime": 1724337700.8462186, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986664, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.8462186, "nlink": 1, "path": "/tmp/devtest-151-30_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 339, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337700.382203, "ctime": 1724337700.382203, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986661, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337700.382203, "nlink": 1, "path": "/tmp/MySQL8-238_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 330, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337699.3501685, "ctime": 1724337699.3501685, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986652, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.3501685, "nlink": 1, "path": "/tmp/mysql-57_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 321, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337701.4182377, "ctime": 1724337701.4182377, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986670, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337701.4182377, "nlink": 1, "path": "/tmp/RADIUS-NAC-100_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 342, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337698.0061235, "ctime": 1724337698.0061235, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986638, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337698.0061235, "nlink": 1, "path": "/tmp/backup-2_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 172, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, {"atime": 1724337699.122161, "ctime": 1724337699.122161, "dev": 1048632, "gid": 0, "gr_name": "root", "inode": 1986631, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1724337699.122161, "nlink": 1, "path": "/tmp/Limesurvey-118_bw_pw_add_gsa_test.csv", "pw_name": "1000", "rgrp": true, "roth": true, "rusr": true, "size": 342, "uid": 1000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}], "matched": 24, "msg": "All paths examined", "skipped_paths": {}}
[WARNING]: Could not match supplied host pattern, ignoring: 192.168.151.241
PLAY [Copy all txt files from localhost to 192.168.151.241] ********************
skipping: no hosts matched
the verbose log.