Skip to Content
Security Automation with Ansible 2
book

Security Automation with Ansible 2

by Akash Mahajan, MADHU AKULA
December 2017
Intermediate to advanced
364 pages
7h 30m
English
Packt Publishing
Content preview from Security Automation with Ansible 2

Code

We use Python for many scripting tasks, but we are not experts in it. But we believe this code is simple enough to understand:

from ansible.module_utils.basic import AnsibleModulemodule = AnsibleModule(    argument_spec=dict(        answer=dict(choices=['yes', 'no'], default='yes'),    ))answer = module.params['answer']if answer == 'no':    module.fail_json(changed=True, msg='Failure! We failed because we answered no.')module.exit_json(changed=True, msg='Success! We passed because we answered yes.')
  1. We are importing some modules.
  2. The second part is just how we need to declare the arguments we will accept for the module.
  3. In our code, we can refer to the arguments the way we have taken the value of the answer variable.
  4. Based on the answer, if it is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementing DevOps with Ansible 2

Implementing DevOps with Ansible 2

Jonathan McAllister
Practical Ansible 2

Practical Ansible 2

Daniel Oh, James Freeman, Fabio Alessandro Locati

Publisher Resources

ISBN: 9781788394512Supplemental Content