Skip to content

sky54000/TI_Generator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TI Generator

summary:

Description

This project create TestInfra scripts to test files. You can easily run it on your Production environment to fix configuration.

Use it

The generator is located in the role ti.generator, you have to set some targets file with the variable TI_HOST_CONF.

Basic example:
playbook.yml:

- hosts: v1
  vars:
   TI_HOST_CONF:
     - name: Fix prod
       file_name: testinfra-v1.py
       file_path: ti_result/
       ti_generator_target_folder:
         - /home/user_test1/
         - /home/user_test2/
     - name: Fix rec
       file_name: testinfra-v2.py
       file_path: ti_result/
       ti_generator_target_folder:
         - /home/user_test2/
         - /home/user_test3/
 roles:
   # - role: provisioner # provisioner create multiple user and folders tree.
   - role: ti.generator

example with include vars:
var/prod.yml:

  TI_HOST_CONF_tmp:
    - name: Fix prod
      file_name: testinfra-v1.py
      file_path: ti_result/
      ti_generator_target_folder:
        - /home/user_test1/
        - /home/user_test2/

var/rec.yml:

TI_HOST_CONF_tmp:
  - name: Fix rec
    file_name: testinfra-v2.py
    file_path: ti_result/
    ti_generator_target_folder:
      - /home/user_test2/
      - /home/user_test3/

playbook.yml:

- hosts: v1
  pre_tasks:
    - set_fact:
        TI_HOST_CONF: []

    - include_vars: vars/prod.yml

    - set_fact:
        TI_HOST_CONF: "{{TI_HOST_CONF}} +[ TI_HOST_CONF_tmp ]"

    - include_vars: vars/rec.yml

    - set_fact:
        TI_HOST_CONF: "{{TI_HOST_CONF}} +[ TI_HOST_CONF_tmp ]"
  roles:
    - role: ti.generator

result for both examples :
ti_result/testinfra-v1.py:

#######################################
# TestInfra generated by Ti-generator #
#######################################
# This tool is an open-source project on Github (https://github.com/kuty22/TI_Generator)


# target: /home/user_test1/
# assert on: ['file_exist', 'user', 'group', mode]
def testinfra_v10(host):
    file_target = host.file('/home/user_test1/')
    assert file_target.user == 'user_test1'
    assert file_target.group == 'user_test1'
    assert file_target.mode == 700

# target: /home/user_test2/
# assert on: ['file_exist', 'user', 'group', mode]
def testinfra_v11(host):
    file_target = host.file('/home/user_test2/')
    assert file_target.user == 'user_test2'
    assert file_target.group == 'user_test2'
    assert file_target.mode == 700

ti_result/testinfra-v2.py:

#######################################
# TestInfra generated by Ti-generator #
#######################################
# This tool is an open-source project on Github (https://github.com/kuty22/TI_Generator)


# target: /home/user_test2/
# assert on: ['file_exist', 'user', 'group', mode]
def testinfra_v20(host):
    file_target = host.file('/home/user_test2/')
    assert file_target.user == 'user_test2'
    assert file_target.group == 'user_test2'
    assert file_target.mode == 700


# target: /home/user_test3/
# assert on: ['file_exist', 'user', 'group', mode]
def testinfra_v21(host):
    file_target = host.file('/home/user_test3/')
    assert file_target.user == 'user_test3'
    assert file_target.group == 'user_test3'
    assert file_target.mode == 700

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%