xhudik
xhudik

Reputation: 2444

how to get commands from ansible playbook

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?

Upvotes: 3

Views: 974

Answers (1)

blong
blong

Reputation: 2713

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.

Upvotes: 5

Related Questions