3

Is there a simple way how to get back what precisely ansible script(playbook) is trying to do?

E.g. I have

- name: Install required packages
  yum: name={{item}} state=present
  with_items:
    - nmp
  become: True 

And I want to get:

sudo yum install nmp

That said, I want to know what commands (OS level) ansible is running. Basically, I need the reverse process to: Ansible and Playbook. How to convert shell commands into yaml syntax?

Community
  • 1
  • 1
xhudik
  • 2,414
  • 1
  • 21
  • 39
  • Just read the code: [`yum.py`](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/os/yum.py). – techraf Apr 21 '17 at 12:47
  • 2
    Verbose `-vvvv` – spinkus Apr 21 '17 at 12:47
  • guys(@techraf, @spinkus), the question whether there is a easy was how to get the commands - not crawling through of tons of logs from -vvvv, or reading code. I need that for 100 commands in ansible playbook – xhudik Apr 21 '17 at 12:49
  • 1
    But Ansible only sometimes runs external commands (actually overall in pretty rare cases), it's mostly Python code and Python libraries. – techraf Apr 21 '17 at 13:43
  • 1
    interesting point @techraf - so you are saying there is no simple "translation" from modules like file (http://docs.ansible.com/ansible/file_module.html) to the OS level command? Only modules like command (http://docs.ansible.com/ansible/command_module.html) - which just run shell + command itself can be "translated" - Do I understand it correctly? – xhudik Apr 21 '17 at 14:11
  • 1
    Yes, you understand it correctly. It's even more complicated as a single module (like `yum`) behaves differently depending on parameters and installed libraries. Other modules must also handle different OS types, etc. – techraf Apr 21 '17 at 14:20
  • 1
    @techraf - write it as a answer - i believe it is valid one – xhudik Apr 21 '17 at 14:50

1 Answers1

5

Summarizing here the central points from comments above [1][2].

Ansible rarely runs external commands, it's mostly Python code & Python libraries being used to control hosts. Therefor, Ansible's "translation" isn't necessarily converting yum (Ansible module) usage into yum (CLI) invocations.

While you may be able to depend on the output, in some cases, by parsing for command sequences in the output of ansible-playbook -vvv foo.yml - the implementation would be flaky at best.

I'd encourage you to keep discussing on this thread what you're trying to accomplish. It's likely there is already a solution, and someone can point you to a tool that already exists.

blong
  • 2,815
  • 8
  • 44
  • 110