Hello!
after switching to hostnames in awx inventory and added ip via ansible_host var, the playbook cannot match them anymore.
There is an survey for the two hosts
Playbook:
---
- name: Generate SSH keypair on remote hosts and distribute keys
hosts:
- "{{ sql_dest_srv }}"
- "{{ sql_src_srv }}"
become: true
tasks:
- name: Output the value of sql_src_srv
ansible.builtin.debug:
msg: "The value of sql_src_srv is: {{ sql_src_srv }}"
- name: Output the value of sql_dest_srv
ansible.builtin.debug:
msg: "The value of sql_dest_srv is: {{ sql_dest_srv }}"
- name: Create SSH keypair in /tmp
hosts: localhost
tasks:
- name: Create SSH keypair in /tmp
ansible.builtin.openssh_keypair:
path: /tmp/id_rsa_remcpyusr
type: rsa
force: true
comment: "remcpyusr"
run_once: true
- name: Distribute the SSH public key
hosts: sql_src_srv
tasks:
- name: Distribute the SSH public key
ansible.builtin.copy:
src: /tmp/id_rsa_remcpyusr.pub
dest: /home/remcpyusr/.ssh/authorized_keys
owner: remcpyusr
mode: '0644'
force: yes
- name: Distribute the SSH private key
hosts: sql_dest_srv
tasks:
- name: Distribute the SSH private key
ansible.builtin.copy:
src: /tmp/id_rsa_remcpyusr
dest: /home/remcpyusr/.ssh/id_rsa
owner: remcpyusr
mode: '0600'
force: yes
- name: Ensure key pair is absent on the controller and hosts
hosts: all
tasks:
- name: Ensure key pair is absent on the controller and hosts
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- /tmp/id_rsa_remcpyusr
- /tmp/id_rsa_remcpyusr.pub
- /home/remcpyusr/.ssh/authorized_keys
- /home/remcpyusr/.ssh/id_rsa
Log:
Enter passphrase for /runner/artifacts/7145/ssh_key_data:
Identity added: /runner/artifacts/7145/ssh_key_data (/runner/artifacts/7145/ssh_key_data)
No config file found; using defaults
PLAY [Generate SSH keypair on remote hosts and distribute keys] ****************
TASK [Gathering Facts] *********************************************************
ok: [testsrv-02]
ok: [testsrv-01]
TASK [Output the value of sql_src_srv] *****************************************
ok: [testsrv-02] => {
"msg": "The value of sql_src_srv is: testsrv-01"
}
ok: [testsrv-01] => {
"msg": "The value of sql_src_srv is: testsrv-01"
}
TASK [Output the value of sql_dest_srv] ****************************************
ok: [testsrv-02] => {
"msg": "The value of sql_dest_srv is: testsrv-02"
}
ok: [testsrv-01] => {
"msg": "The value of sql_dest_srv is: testsrv-02"
}
PLAY [Create SSH keypair in /tmp] **********************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [Create SSH keypair in /tmp] **********************************************
changed: [localhost] => {"changed": true, "comment": "remcpyusr", "filename": "/tmp/id_rsa_remcpyusr", "fingerprint": "SHA256:R7mlu1QA3BZa53+iA1tv8zGKjqVMAiDIEkl7BNBmoIY", "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCyjbIE9/VvkyqeoRRfA24C1Es580kodNpH6WCrOfmXZuNZEA183cnanMIlk42IxGSTqotdf/LrUTRBKhmoHrxbYQmhdBkF2Se0mRSr0g5vtFocEh2OmYPheqQZ9XZhtMX4eaw+l2qnpYijVBMI2+s+1cIbCzfKGzt1VomI2FdaA8gcFzrdGljCQn4Xhy/haJIQWTiBKMSrp/tpXmS14cp7vqf0SpqB8NmEoSBhG2470q3Q3u5AuVdrpQ4bV/pbGTW+Zz/IixGYVeDoQFiDyj//TIdv+pQRu+cyKGumKexgzqtxnuMNfsk/4cA9ZEy01TczDuQcYyd5G4vDOEhttxp0n/cPGc25F2t5ipbRHUFf91aYe07Dzh9BOMgxNnIpax9Ls/Toswg3/qkc5cYIJczGrvYLu9mLfJm6B2ls+QxFtIUcoSdnIm0VDBopC5BlB6V1G0lS8CcdKyyXHP5AzHf7qjoITfqRqKSfDdFB3Qmn9GiiJitdDF7UQWE5V6V/9XXJ4EkNKWw9rRNtG1whLVxsb+U7okVDOfOpAwUz/gUr2PmeHtr8cNVouYX9GSLRc62ASXi8A106MY++b+joOz2R5/viRneN9rfmv8MBlMKirQ3Iw98U7sbcAPVlNWf9Rgtlw10BTQvl2WauvVIlwdQPa/LWzZS7+JufJ5pZlOdymw==", "size": 4096, "type": "rsa"}
[WARNING]: Could not match supplied host pattern, ignoring: sql_src_srv
PLAY [Distribute the SSH public key] *******************************************
skipping: no hosts matched
[WARNING]: Could not match supplied host pattern, ignoring: sql_dest_srv
PLAY [Distribute the SSH private key] ******************************************
skipping: no hosts matched
PLAY [Ensure key pair is absent on the controller and hosts] *******************
TASK [Gathering Facts] *********************************************************
ok: [testsrv-02]
ok: [testsrv-01]
TASK [Ensure key pair is absent on the controller and hosts] *******************
ok: [testsrv-01] => (item=/tmp/id_rsa_remcpyusr) => {"ansible_loop_var": "item", "changed": false, "item": "/tmp/id_rsa_remcpyusr", "path": "/tmp/id_rsa_remcpyusr", "state": "absent"}
ok: [testsrv-02] => (item=/tmp/id_rsa_remcpyusr) => {"ansible_loop_var": "item", "changed": false, "item": "/tmp/id_rsa_remcpyusr", "path": "/tmp/id_rsa_remcpyusr", "state": "absent"}
ok: [testsrv-01] => (item=/tmp/id_rsa_remcpyusr.pub) => {"ansible_loop_var": "item", "changed": false, "item": "/tmp/id_rsa_remcpyusr.pub", "path": "/tmp/id_rsa_remcpyusr.pub", "state": "absent"}
ok: [testsrv-02] => (item=/tmp/id_rsa_remcpyusr.pub) => {"ansible_loop_var": "item", "changed": false, "item": "/tmp/id_rsa_remcpyusr.pub", "path": "/tmp/id_rsa_remcpyusr.pub", "state": "absent"}
ok: [testsrv-01] => (item=/home/remcpyusr/.ssh/authorized_keys) => {"ansible_loop_var": "item", "changed": false, "item": "/home/remcpyusr/.ssh/authorized_keys", "path": "/home/remcpyusr/.ssh/authorized_keys", "state": "absent"}
ok: [testsrv-02] => (item=/home/remcpyusr/.ssh/authorized_keys) => {"ansible_loop_var": "item", "changed": false, "item": "/home/remcpyusr/.ssh/authorized_keys", "path": "/home/remcpyusr/.ssh/authorized_keys", "state": "absent"}
ok: [testsrv-01] => (item=/home/remcpyusr/.ssh/id_rsa) => {"ansible_loop_var": "item", "changed": false, "item": "/home/remcpyusr/.ssh/id_rsa", "path": "/home/remcpyusr/.ssh/id_rsa", "state": "absent"}
ok: [testsrv-02] => (item=/home/remcpyusr/.ssh/id_rsa) => {"ansible_loop_var": "item", "changed": false, "item": "/home/remcpyusr/.ssh/id_rsa", "path": "/home/remcpyusr/.ssh/id_rsa", "state": "absent"}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
testsrv-01 : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
testsrv-02 : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Thank you again for your support!!