-
Notifications
You must be signed in to change notification settings - Fork 2
[WIP] Add minimal playbooks to setup IPA client on host #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ganto
wants to merge
1
commit into
inofix:master
Choose a base branch
from
ganto:feature/ipa-client
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #* This playbook exports the kerberos host keytab from IPA and deploys | ||
| #* it on a host to /etc/krb5.keytab. | ||
| #* It requires your Ansible user to have SSH access to the IPA server | ||
| #* and a valid kerberos ticket with the required export permissions | ||
| #* already issued. | ||
| #* No arguments are needed. | ||
|
|
||
| - name: Export Kerberos keytab from IPA and deploy it on host | ||
| hosts: host.Virtual,&os.debian_buster | ||
|
|
||
| vars: | ||
| deploy_keytab__ipa_host_delegation: "{{ ipa.servers|first | default('ipa.' + ansible_domain) }}" | ||
|
|
||
| tasks: | ||
| - name: Query keytab | ||
| become: True | ||
| stat: | ||
| path: /etc/krb5.keytab | ||
| register: deploy_keytab__register_keytab | ||
|
|
||
| - name: Run tasks to install host keytab | ||
| block: | ||
| - name: Create temporary directory | ||
| delegate_to: "{{ deploy_keytab__ipa_host_delegation }}" | ||
| tempfile: | ||
| state: directory | ||
| prefix: "keytab." | ||
| register: deploy_keytab__register_tempdir | ||
|
|
||
| - name: Export host keytab | ||
| delegate_to: "{{ deploy_keytab__ipa_host_delegation }}" | ||
| command: > | ||
| /usr/sbin/ipa-getkeytab | ||
| -s {{ deploy_keytab__ipa_host_delegation }} | ||
| -p host/{{ ansible_fqdn }} | ||
| -k {{ deploy_keytab__register_tempdir.path }}/krb5.keytab | ||
|
|
||
| - name: Fetch keytab from IPA server | ||
| delegate_to: "{{ deploy_keytab__ipa_host_delegation }}" | ||
| fetch: | ||
| src: "{{ deploy_keytab__register_tempdir.path }}/krb5.keytab" | ||
| # copy file to playbook directory | ||
| dest: "./" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any dedicated location for temporarily storing files on the Ansible controller? Or should I create a tmpdir there too? |
||
| flat: yes | ||
|
|
||
| - name: Copy keytab to host | ||
| become: True | ||
| copy: | ||
| src: "krb5.keytab" | ||
| dest: "/etc/krb5.keytab" | ||
| owner: root | ||
| group: root | ||
| mode: 0600 | ||
|
|
||
| - name: Remove temporary directory | ||
| delegate_to: "{{ deploy_keytab__ipa_host_delegation }}" | ||
| file: | ||
| path: "{{ deploy_keytab__register_tempdir.path }}" | ||
| state: absent | ||
|
|
||
| - name: Remove temporary keytab | ||
| delegate_to: localhost | ||
| file: | ||
| path: "krb5.keytab" | ||
| state: absent | ||
|
|
||
| when: not deploy_keytab__register_keytab.stat.exists | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #* This playbook registers a new host on the IPA domain which will | ||
| #* create an internal DNS record and setup user authentication via | ||
| #* LDAP/Kerberos. | ||
| #* Use '-a' to pass parameters to ansible (as '-e'). | ||
| #* No arguments are mandatory. | ||
|
|
||
| - name: Register host on IPA domain | ||
| hosts: host.Virtual,&os.debian_buster | ||
|
|
||
| vars: | ||
| setup_ipa_client__ipa_host_delegation: "{{ ipa.servers|first | default('ipa.' + ansible_domain) }}" | ||
|
|
||
| tasks: | ||
| - name: Check IPA server login | ||
| delegate_to: "{{ setup_ipa_client__ipa_host_delegation }}" | ||
| run_once: true | ||
| ping: | ||
|
|
||
| - name: Check for valid kerberos ticket | ||
| delegate_to: "{{ setup_ipa_client__ipa_host_delegation }}" | ||
| changed_when: false | ||
| command: klist | ||
|
|
||
| - name: Query IPA for host | ||
| delegate_to: "{{ setup_ipa_client__ipa_host_delegation }}" | ||
| # If host not joined yet, return code 2 | ||
| failed_when: setup_ipa_client__register__host_show.rc not in [0, 2] | ||
| command: ipa host-show "{{ ansible_fqdn }}" | ||
| register: setup_ipa_client__register__host_show | ||
|
|
||
| - name: Add host to IPA | ||
| delegate_to: "{{ setup_ipa_client__ipa_host_delegation }}" | ||
| command: "ipa host-add --ip-address={{ ansible_default_ipv4.address }} {{ ansible_fqdn }}" | ||
| when: setup_ipa_client__register__host_show.rc != 0 | ||
|
|
||
| - import_playbook: deploy-keytab.yml |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this. Should we make a new class
host.IPAClientor something? Or any other suggestion how to restrict this to designated hosts?