ansible-ruby icon indicating copy to clipboard operation
ansible-ruby copied to clipboard

Variable AST

Open wied03 opened this issue 9 years ago • 0 comments

Need to at least allow/parse return values from modules (see ec2_ami).

Could allow this:

task 'Copy something over' do
  result = foobar do
    src '/file1.conf'
    dest '/file2.conf'
  end

  become
  notify 'handler1'
  changed_when "'no upgrade' in #{result.stdout}"
end

to become this:

task 'Copy something over' do
  result = foobar do
    src '/file1.conf'
    dest '/file2.conf'
  end

  become
  notify 'handler1'
  changed_when result.stdout.include? 'no upgrade'
end

The first case already compiles to this:


---
# This is a generated YAML file by ansible-ruby, DO NOT EDIT
- name: Copy something over
  copy:
    src: "/file1.conf"
    dest: "/file2.conf"
  become: true
  register: result_1
  changed_when: "'no upgrade' in result_1.stdout"
  notify:
  - handler1

Basically it creates a light AST that would mimic the Ruby string/primitive methods and convert that to the Python/YAML/jinja stuff. Would want to cover basics only. More sophisticated stuff should be in custom modules. Even this might be difficult since different modules return different types of results.

Also could make the with_dict syntax easier so that you don't have to do value.stuff and instead can do value[:stuff]. Might be a slippery slope there though.

wied03 avatar Aug 20 '16 21:08 wied03