Ansible Advanced Course - Labs - Dynamic Inventory - Q6

I can’t solve this question, need your kind assist.

It would appear that when we upgraded this lab from CentOS 7 to CentOS 9 Stream, that we broke a number of things. But you can get this lab to work, it turns out, because it’s easy to fix ec2.py, by making the script work with python3:

  • Change the first line of the script to:
#!/usr/bin/env python3
  • Change Line 33 of the script to:
        print(json.dumps(self.inventory));

If you do this, then running ansible-inventory -i ec2.py --host 172.20.1.109 will work and return an answer.

I’ll tell the lab team to fix the lab to work with python3.

This has now been fixed. Sorry for the hassle!