Skip to main content
Glama
tarnover
by tarnover

vault_encrypt_string

Encrypt sensitive strings securely using Ansible Vault; specify the string, vault ID, and password file to generate encrypted output for secure storage or usage.

Instructions

Encrypt a string using Ansible Vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNo
stringYes
vault_idNo
vault_password_fileNo

Implementation Reference

  • Handler function that spawns ansible-vault encrypt_string process, pipes the input string to stdin, and returns the encrypted output.
    export async function encryptString(options: VaultEncryptStringOptions): Promise<string> {
      return new Promise((resolve, reject) => {
        const args = ['encrypt_string'];
        
        // Add vault ID if specified
        if (options.vault_id) {
          args.push(`--vault-id=${options.vault_id}`);
        }
        
        // Add vault password file if specified
        if (options.vault_password_file) {
          args.push(`--vault-password-file=${options.vault_password_file}`);
        }
        
        // Add name if specified
        if (options.name) {
          args.push(`--name=${options.name}`);
        }
        
        // Add --stdin flag to read from stdin
        args.push('--stdin');
    
        console.error(`Executing: ansible-vault ${args.join(' ')} (with string piped to stdin)`);
        const vaultProcess = spawn('ansible-vault', args, { stdio: ['pipe', 'pipe', 'pipe'] });
    
        let stdoutData = '';
        let stderrData = '';
    
        vaultProcess.stdout.on('data', (data) => {
          stdoutData += data.toString();
        });
    
        vaultProcess.stderr.on('data', (data) => {
          stderrData += data.toString();
        });
    
        vaultProcess.on('close', (code) => {
          if (code === 0) {
            resolve(stdoutData.trim());
          } else {
            const errorMessage = stderrData || `ansible-vault exited with code ${code}`;
            reject(new AnsibleExecutionError(`Error encrypting string: ${errorMessage}`, stderrData));
          }
        });
    
        vaultProcess.on('error', (err) => {
          reject(new AnsibleExecutionError(`Failed to start ansible-vault: ${err.message}`));
        });
    
        // Write the string to encrypt to stdin
        vaultProcess.stdin.write(options.string);
        vaultProcess.stdin.end();
      });
    }
  • Zod schema defining input parameters for the vault_encrypt_string tool: string to encrypt, optional vault_id, vault_password_file, and name.
    export const VaultEncryptStringSchema = z.object({
      string: z.string().min(1, 'String to encrypt is required'),
      vault_id: z.string().optional(),
      vault_password_file: z.string().optional(),
      name: z.string().optional(),
    });
    
    export type VaultEncryptStringOptions = z.infer<typeof VaultEncryptStringSchema>;
  • Registration of the 'vault_encrypt_string' tool in the toolDefinitions map, linking schema and handler.
    vault_encrypt_string: {
      description: 'Encrypt a string using Ansible Vault',
      schema: VaultEncryptStringSchema,
      handler: vault.encryptString,
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tarnover/mcp-ansible'

If you have feedback or need assistance with the MCP directory API, please join our Discord server