News for hackers. Stuff that matters.
Re:That's a Lot of YAML by karczex on Friday April 11, 2025 @07:52AM (#43652795)
In most cases Yaml is bizarre kind of DSL with tricky way of API interaction. For instance - I don't understand why exactly the same Ansible API isn't just python library?
Re:That's a Lot of YAML by mdaniel on Saturday April 12, 2025 @01:03AM (#43661510)
For the same reason any DSL exists: because the programming representation is a lot more verbose than the DSL, due to the computers not currently honoring the "you know what I meant" flag

  #!/usr/bin/env python3
  """A made up example of the line noise"""
  from ansible import *
  def main():
    hosts = ["localhost"]
    for h in hosts:
      run_one_host(h)
  def run_one_host(inventory_hostname: str):
    connection = ansible.builtin.ssh(inventory_hostname)
    print("sniff out the machine's os")
    host_vars = ansible.builtin.setup(gather_subset="os", connection)
    if host_vars["distribution"] == "ubuntu":
      dest = "/etc/apt"
    else ...
      dest = "/etc/something else"
         
    print("do something awesome")
    copy_ok = ansible.builtin.copy(src="./some_file", dest=dest, connection)
    ...

That said, I can't readily imagine why you couldn't do exactly what you said because the AnsibleModule[1] contract is JSON over stdin/stdout (and one can write Ansible modules in any programming language[2] - they just default to Python)

1: https://github.com/ansible/ansible/blob/v2.18.4/lib/ansible/...

2: https://docs.ansible.com/ansible-core/2.18/dev_guide/develop... and https://github.com/ansible/ansible/blob/v2.18.4/test/integra...

Re:That's a Lot of YAML by vrighter on Monday April 14, 2025 @08:41AM (#43680661)
python (as much as I personally dislike the language itself) has clean syntax for sets, dicts and arrays. Which are the data structures you use in a playbook. Ansible as python instead of yaml can be made to look very similar to current playbooks. But saner. And easier to script.
Re:That's a Lot of YAML by mdaniel on Monday April 14, 2025 @11:25AM (#43682339)
Oh, sorry I misunderstood, then. So, closer to the troposphere version of using python to generate json to feed into ansible?
Re:That's a Lot of YAML by vrighter on Sunday April 20, 2025 @03:44AM (#43742210)
ansible is already written in python. Just eliminate the json/yaml and let us use it from python directly.