ansible / workshops

Training Course for Ansible Automation Platform
MIT License
1.75k stars 1.14k forks source link

Ansible Security Automation Workshop - lab-inventory/hosts not parsing on cli playbook runs #1723

Closed mkbredem closed 2 years ago

mkbredem commented 2 years ago

Problem Summary

Exercise 1.2.5 (in security workshop)

run: $ ansible-navigator run whitelist_attacker.yml --mode stdout

[WARNING]: Failed to parse /home/student1/lab_inventory/hosts with yaml plugin: YAML inventory has invalid structure, it should be a dictionary, got: <class 'ansible.parsing.yaml.objects.AnsibleUnicode'> [WARNING]: Failed to parse /home/student1/lab_inventory/hosts with ini plugin: /home/student1/lab_inventory/hosts:8: Expected key=value host variable assignment, got: run [WARNING]: Unable to parse /home/student1/lab_inventory/hosts as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: Could not match supplied host pattern, ignoring: checkpoint

PLAY [Whitelist Attacker] ** skipping: no hosts matched

PLAY RECAP *****

[student1@ansible-1 ~]$ ansible-navigator run whitelist_attacker.yml --mode stdout [WARNING]: Failed to parse /home/student1/lab_inventory/hosts with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 2 (char 1) Syntax Error while loading YAML. found unexpected ':' The error appears to be in '/home/student1/lab_inventory/hosts': line 1, column 5, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: [all:vars] ^ here [WARNING]: Failed to parse /home/student1/lab_inventory/hosts with ini plugin: /home/student1/lab_inventory/hosts:11: Expected key=value host variable assignment, got: run [WARNING]: Unable to parse /home/student1/lab_inventory/hosts as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' [WARNING]: Could not match supplied host pattern, ignoring: checkpoint

PLAY [Whitelist Attacker] ** skipping: no hosts matched

PLAY RECAP *****

the playbook executes without error, but obviously doesn't do anything since it can't find a host to target. Syntax is what is preloaded by rhpds provisioner.

Syntax and host file untouched since it was preloaded by rhpds provisioner.

[all:vars] ansible_user=student1 ansible_ssh_pass=v1ClNzuUU2wivz ansible_port=22

[control] ansible ansible_host=3.17.79.132 private_ip=172.16.7.195

[attack] attacker ansible_host=18.221.195.144 ansible_user=ec2-user private_ip=172.16.207.22 private_ip2=172.17.253.233 ansible-navigator run whitelist_attacker.yml --mode stdout [siem] qradar ansible_host=3.145.34.166 ansible_user=admin private_ip=172.16.21.134 ansible_httpapi_pass="Ansible1!" ansible_connection=httpapi ansible_httpapi_use_ssl=yes ansible_httpapi_validate_certs=False ansible_network_os=ibm.qradar.qradar

[ids] snort ansible_host=3.145.174.29 ansible_user=ec2-user private_ip=172.16.214.55 private_ip2=172.17.119.28

[firewall] checkpoint ansible_host=13.59.127.127 ansible_user=admin ansible_password=admin123 private_ip=172.16.164.182 ansible_network_os=checkpoint ansible_connection=httpapi ansible_httpapi_use_ssl=yes ansible_httpapi_validate_certs=no

[windows] windows-ws ansible_host=18.116.51.169 ansible_user=Administrator ansible_pass=1NUIBv61g7cyDW ansible_port=5986 ansible_connection=winrm ansible_winrm_server_cert_validation=ignore private_ip=172.16.130.112

Issue Type

Bug

Extra vars file

no vars.yml file

Ansible Playbook Output

WARNING]: Failed to parse /home/student1/lab_inventory/hosts with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 2 (char 1) Syntax Error while loading YAML. found unexpected ':' The error appears to be in '/home/student1/lab_inventory/hosts': line 1, column 5, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: [all:vars] ^ here [WARNING]: Failed to parse /home/student1/lab_inventory/hosts with ini plugin: /home/student1/lab_inventory/hosts:11: Expected key=value host variable assignment, got: run [WARNING]: Unable to parse /home/student1/lab_inventory/hosts as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' [WARNING]: Could not match supplied host pattern, ignoring: checkpoint

PLAY [Whitelist Attacker] ** skipping: no hosts matched

PLAY RECAP *****

Ansible Version

ansible [core 2.12.2] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/student1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.8/site-packages/ansible ansible collection location = /home/student1/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] jinja version = 2.10.3 libyaml = True

Ansible Configuration

ACTION_WARNINGS(/etc/ansible/ansible.cfg) = False COLLECTIONS_ON_ANSIBLE_VERSION_MISMATCH(/etc/ansible/ansible.cfg) = ignore DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/home/student1/lab_inventory/hosts'] DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = yaml DEFAULT_TIMEOUT(/etc/ansible/ansible.cfg) = 60 DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False INTERPRETER_PYTHON(/etc/ansible/ansible.cfg) = auto_silent PERSISTENT_COMMAND_TIMEOUT(/etc/ansible/ansible.cfg) = 200 PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 200 RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False SYSTEM_WARNINGS(/etc/ansible/ansible.cfg) = False

Ansible Execution Node

CLI Ansible (Ansible Core)

Operating System

Red Hat Enterprise Linux release 8.6 (Ootpa)

mkbredem commented 2 years ago

Disregard. I deleted the RHPDS environment and reordered it. Now I don't have the error