It's implements ansible connector that enable you to connect to a systemd-nspawn container.
If connecting with nsenter, you need root privilege.
- Create your container.
- Add nsenter.py to your connectoin plugin's directory.
- Specify your container on your Ansible Inventory.
- Add nsenter connection settings and become settings to your Ansible playbook.
- Run ansible-playbook command with K option.
You must create systemd-nspawn container under /var/lib/machines on Fedora 22.
And then, you must start container with # machinectl start <container_name>
.
If you finish steps below, you can see this directory structure.
$ tree . ├── connection_plugins │ └── nsenter.py ├── hosts └── playbook.yml
Create connection_plugin directory under Ansible directory.
$ cd /path/to/ansible/working/dir/ $ mkdir connection_plugins $ curl https://raw.githubusercontent.com/jptomo/ansible-nsenter/master/nsenter.py -o connection_plugins/nsenter.py
Specify your container on your Ansible Inventory.
Like this
$ cat > hosts <container_name>
Add Ansible playbook.
Like this
$ cat > playbook.yml --- - hosts: all connection: nsenter become: yes tasks: - command: uname -a register: foo - debug: msg="{{foo}}"
You must specify
connection: nsenter
andbecome: yes
.Run ansible-playbook command with K option.
The nsenter connection plusgin needs sudo permission, and if you run command below, you shoud specify your current user's password.
$ ansible-playbook -i hosts playbook.yml -K