Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
|pic1| |pic2| |pic3| |pic4|
#################################### A Simple Ansible Inventory Generator ####################################
=Overview=
This simple library makes it easier to write the glue code between infrastructure bringup/orchestration and software provisioning stages of a one-click deployment.
Head over to the wiki page <https://github.com/rsjethani/ansinv/wiki#welcome-to-the-ansinv-wiki>
_ for more explanation about this project.
=Installation=
::
pip install ansinv
=Working with inventory hosts=
host variables <https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#host-variables>
_:::
host1 = ansinv.AnsibleHost("192.168.10.11", affinity=12, scan="no")
AnsibleHost.name
attribute:::
print(host1.name)
AnsibleHost.hostvars
attribute:::
print(host1.hostvars["scan"]) host1.hostvars["affinity"] = 5 host1.hostvars.update(x=100)
=Working with inventory groups=
group variables <https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#group-variables>
_:::
group1 = ansinv.AnsibleGroup("group1", ssh_port=8800)
AnsibleGroup.name
attribute:::
print(group1.name)
AnsibleGroup.groupvars
attribute:::
print(group1.groupvars["ssh_port"]) group1.groupvars["ssh_port"] = 22 group1.groupvars.update(x=100)
AnsibleGroup.add_hosts
method:::
group1.add_hosts(host1, host2, ...) # host1, host2, etc. must already exist group1.add_hosts(ansinv.AnsibleHost("192.168.12.12", hostvar1="value")) # creating and adding hosts at the same time
Please note: Adding a host actually creates a copy of the host object under the group. So to make modifications to a host object after it has been added, use AnsibleGroup.host
method as described below.
AnsibleGroup.host('hostname')
method:::
group1.host("192.168.1.12").hostvars["hostvar1"] = "new value"
Please note: The host() method will always return the first occurrence of the given 'hostname', even if there are multiple hosts with same name in the group. This behavior assumes that even though you are allowed to have multiple hosts with same name but you will never actually require such a case.
AnsibleGroup.hosts
attribute:::
print(group1.hosts[0].name)
AnsibleGroup.add_children
method:::
child1 = AnsibleGroup("master") child2 = AnsibleGroup("worker") parent = AnsibleGroup("cluster") parent.add_children(child1, child2) parent.add_children(parent) # ValueError when trying to add itself as a child child1.add_children(parent) # ValueError when trying to add a parent group as a child
AnsibleGroup.is_parent_of
method:::
group1.is_parent_of(group2) # Returns a bool value
AnsibleGroup.is_child_of
method:::
group1.is_child_of(group2) # Returns a bool value
AnsibleGroup.children
attribute:::
print(group1.children[0].name)
=Working with the inventory itself=
::
inv = AnsibleInventory() # empty inventory inv = AnsibleInventory(AnsibleHost("h1"), AnsibleHost("h2")) # inventory initialized with two ungrouped hosts
AnsibleInventory.add_hosts
method:::
h1 = AnsibleHost("h1") h2 = AnsibleHost("h2") inv.add_hosts(h1, h2)
Please note: The hosts added directly to the inventory are 'ungrouped' hosts i.e. they will not appear under other groups.
AnsibleInventory.add_groups
method:::
g1 = AnsibleGroup("g1") g2 = AnsibleGroup("g2") inv.add_groups(g1, g2)
Please note: Adding a host/group actually creates a copy of the host/group object under the inventory. So to make modifications to a host/group object after it has been added, use AnsibleInventory.host(hostname)
/AnsibleInventory.group(groupname)
methods as described below.
AnsibleInventory.host
method:::
print(inv.host("h1")) inv.host("h1").hostvars["somevar"] = 111 # modify an ungrouped host after it has been added to the inventory
AnsibleInventory.group('groupname')
method:::
inv.group("g1").groupvars["x"] = 1111 inv.group("g1").host("h1").hostvars["somevar"] = 333
Please note: The group() method will always return the first occurrence of the given 'groupname', even if there are multiple groups with same name in the inventory. This behavior assumes that even though you are allowed to have multiple groups with same name but you will never actually require such a case.
AnsibleInventory.groups
attribute:::
for grp in inv.groups: print(grp.name)
The string version of the inventory is in the INI format which you can simply write to a file and pass the file to Ansible. ::
inv = AnsibleInventory() ... # add some groups and hosts print(str(inv)) with open("inventory", "w") as f: f.write(str(inv))
For more explanation and a full example please visit the wiki page <https://github.com/rsjethani/ansinv/wiki#welcome-to-the-ansinv-wiki>
_.
.. |pic1| image:: https://img.shields.io/badge/License-MIT-yellow.svg :target: https://opensource.org/licenses/MIT
.. |pic2| image:: https://badge.fury.io/py/ansinv.svg :target: https://pypi.org/project/ansinv
.. |pic3| image:: https://travis-ci.com/rsjethani/ansinv.svg?branch=master :target: https://travis-ci.com/rsjethani/ansinv
.. |pic4| image:: https://codecov.io/gh/rsjethani/ansinv/branch/master/graph/badge.svg :target: https://codecov.io/gh/rsjethani/ansinv
FAQs
Generate Ansible Inventory
We found that ansinv demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.