To configure your inventory dynamically you need to use python scripts. You can download the script from the below-given link.
After that, you can do SSH in your EC2 instance and can configure something. You can take help from the below playbook.
- hosts: all
- name: Install httpd