how is software defined infrastructure related to devops?
if I setup automate deployment of code, is this considered devops?


Sure, automating everything is a big part of DevOps.


  I tried ansible but I prefer writing my own code for learning


Now, this is laudable, but using Ansible (or Puppet or Chef or ...) would be "learning" as well. The benefit of using established tools over DIY is that if/when you meet other developers, you have a common toolset to work with. Doing it yourself is nice sometimes as well, but basing a whole software development process on 100% self-written tools (from scratch) is not a good idea, unless you have deeply evaluated the existing tools and consider them all unfit for the purpose. 

When your team grows and you encounter a new developer - is it more likely that they already know about Ansible, or that they know about the code you wrote?

Also, the fact that the tools mentioned above do not do their stuff in the "code" directly, but that they have text files which configure them, is important as well. It abstracts the configuration stuff away from actual code, which will be hard to maintain a few years down the road, no matter how good you are.