Idempotency
Modules are also idempotent. Idempotence is a nice property because it means that it is safe to run an Ansible playbook multiple times against a server.
- name: Ensure deploy user exists
user:
name: testuser
group: tester
If the "testuser" user does not exist, Ansible will create it. If it does exist,Ansible will not do anything.
In October 2015, Red Hat bought Ansible, Inc.
IBM bought Red Hat in 2019.
ansible-pull
ansible-pull -U https://github.com/<compnay>/repo.git -C main site.yml
-U → Git repository URL
-C → Branch name
-i → Inventory
-d → Destination directory
*/30 * * * * /usr/bin/ansible-pull -U https://github.com/company/repo.git site.yml
Installing Ansible
$ brew install ansible
on the target systems, assuming that the Linux/macOS/BSD systems have Python installed and that Windows machines have PowerShell.
Install Ansible using one of the Python package managers
$ pip3 install --user ansible==2.9.27
To worrk with Ansible Tower or AWX, then you should install the same version of ansible-core on your workstation.
python virtualenv
If you work on multiple projects, you should install Ansible into a Python virtualenv.
This lets you avoid interfering with your system Python or cluttering your user environment. Using Python’s venv module and pip3, you can install just what you need to work on for each project:
$ python3 -m venv .venv --prompt A
$ source .venv/bin/activate
(A)
During activation of the environment, your shell prompt will change to (A) as a reminder. Enter deactivate to leave the virtual environment.
Manage Windows systems remotely, with PowerShell over WinRM under the hood.
ansible-builder
ansible-builder is a tool that aids in creating execution environments by controlling the execution of Ansible from within a container for single purpose automation workflows. It is based on the directory layout of ansible-runner.
Inventory
Ansible can manage only the servers it explicitly knows about. you provide Ansible with information about servers by specifying them in an inventory.
$ vi inventory
[webservers]
testserver ansible_port=2222
[webservers:vars]
ansible_host=<ip>
ansible_user=<user_name>
No comments:
Post a Comment