commit cdd7baf40e46963a46520bec08d849d3ff56582e Author: Nicola Belluti Date: Wed May 8 13:08:16 2024 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..424bd26 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ansible/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b7f05d --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..a4df8da --- /dev/null +++ b/ansible.cfg @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a6a02cd --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6bfd2c2 --- /dev/null +++ b/flake.nix @@ -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 + ]; + + }; + }; +} diff --git a/inventory/test-inventory.yml b/inventory/test-inventory.yml new file mode 100644 index 0000000..1aee67f --- /dev/null +++ b/inventory/test-inventory.yml @@ -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 diff --git a/playbooks/test_playbook.yml b/playbooks/test_playbook.yml new file mode 100644 index 0000000..58c3dc1 --- /dev/null +++ b/playbooks/test_playbook.yml @@ -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 diff --git a/roles/test_role/README.md b/roles/test_role/README.md new file mode 100644 index 0000000..2790340 --- /dev/null +++ b/roles/test_role/README.md @@ -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` | ❌ | | diff --git a/roles/test_role/defaults/main.yml b/roles/test_role/defaults/main.yml new file mode 100644 index 0000000..884f345 --- /dev/null +++ b/roles/test_role/defaults/main.yml @@ -0,0 +1 @@ +test_role__hello_world_string: Hello, World! diff --git a/roles/test_role/tasks/main.yml b/roles/test_role/tasks/main.yml new file mode 100644 index 0000000..7975668 --- /dev/null +++ b/roles/test_role/tasks/main.yml @@ -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 diff --git a/roles/test_role/templates/ansible.txt.j2 b/roles/test_role/templates/ansible.txt.j2 new file mode 100644 index 0000000..921503f --- /dev/null +++ b/roles/test_role/templates/ansible.txt.j2 @@ -0,0 +1,3 @@ +{{ ansible_managed | comment('plain') }} + +{{ test_role__lorem_ipsum_string }}