Initial commit

This commit is contained in:
Nicola Belluti 2024-05-08 13:08:16 +02:00
commit cdd7baf40e
11 changed files with 139 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.ansible/

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# Template | Ansible 👷🏻‍♂️
A template for an Ansible repository
# Requirements
To use this repository run:
```sh
git clone https://git.nicolabelluti.me/nicolabelluti/template-ansible
cd template-ansible
nix develop
```

32
ansible.cfg Normal file
View File

@ -0,0 +1,32 @@
[defaults]
# (path) The default root path for Ansible config files on the controller.
home=./.ansible
# (boolean) If you have cowsay installed but want to avoid the 'cows' (why????), use this.
nocows = true
# (pathlist) Comma separated list of Ansible inventory sources
inventory = ./inventory
# (string) Sets the macro for the 'ansible_managed' variable available for :ref:`ansible_collections.ansible.builtin.template_module` and :ref:`ansible_collections.ansible.windows.win_template_module`. This is only relevant for those two modules.
ansible_managed = This file is managed with Ansible
# (pathspec) Colon separated paths in which Ansible will search for Roles.
roles_path = ./roles
# (string) Set the main callback used to display Ansible output. You can only have one at a time.
# You can have many other callbacks, but just one can be in charge of stdout.
# See :ref:`callback_plugins` for a list of available options.
stdout_callback = yaml
[connection]
# (boolean) This is a global option, each connection plugin can override either by having more specific options or not supporting pipelining at all.
# Pipelining, if supported by the connection plugin, reduces the number of network operations required to execute a module on the remote server, by executing many Ansible modules without actual file transfer.
# It can result in a very significant performance improvement when enabled.
# However this conflicts with privilege escalation (become). For example, when using 'sudo:' operations you must first disable 'requiretty' in /etc/sudoers on all managed hosts, which is why it is disabled by default.
# This setting will be disabled if ``ANSIBLE_KEEP_REMOTE_FILES`` is enabled.
pipelining = true
[diff]
# (bool) Configuration toggle to tell modules to show differences when in 'changed' status, equivalent to ``--diff``.
always = true

27
flake.lock generated Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1714906307,
"narHash": "sha256-UlRZtrCnhPFSJlDQE7M0eyhgvuuHBTe1eJ9N9AQlJQ0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "25865a40d14b3f9cf19f19b924e2ab4069b09588",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View File

@ -0,0 +1,25 @@
{
description = "Ansible";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [
openssh
sshpass
ansible
ansible-lint
];
};
};
}

View File

@ -0,0 +1,8 @@
test_hosts:
hosts:
127.0.0.1:
127.0.0.2:
127.0.0.3:
vars:
ansible_user: username
ansible_ssh_pass: password

View File

@ -0,0 +1,7 @@
- name: Test Playbook
hosts: test_hosts
roles:
- name: Test Role
role: test_role
vars:
test_role__lorem_ipsum_string: Lorem Ipsum is simply dummy text

10
roles/test_role/README.md Normal file
View File

@ -0,0 +1,10 @@
# Test Role
A brief description about the role...
## Variables
| Name | Is Required? | Default |
|:-------------------------------:|:------------:|:-------------:|
| `test_role__hello_world_string` | ✔️ | Hello, World! |
| `test_role__lorem_ipsum_string` | ❌ | |

View File

@ -0,0 +1 @@
test_role__hello_world_string: Hello, World!

View File

@ -0,0 +1,12 @@
- name: Ping
ansible.builtin.ping:
- name: Print an "Hello, World!"
ansible.builtin.debug:
msg: "{{ test_role__hello_world_string }}"
- name: Test the `ansible_managed` variable
ansible.builtin.template:
dest: /tmp/ansible.txt
src: ansible.txt.j2
mode: preserve

View File

@ -0,0 +1,3 @@
{{ ansible_managed | comment('plain') }}
{{ test_role__lorem_ipsum_string }}