I really don't see the error in the following ansible task:
- name: Ensure home directories are created upon login
lineinfile:
path: /etc/pam.d/common-session
search_string: 'pam_mkhomedir\.so'
insertafter: 'pam_sss.so'
line: 'session required pam_mkhomedir.so skel=/etc/skel/ umask=0022'
tags:
- ldap
- pam
- config
When executed I get the following error:
fatal: [ourcq]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (lineinfile) module: search_string Supported parameters include: attributes, backrefs, backup, create, firstmatch, group, insertafter, insertbefore, line, mode, owner, path, regexp, selevel, serole, setype, seuser, state, unsafe_writes, validate"}
I found a solution that does what I want:
add the line line after the line containing pam_sss.so if the line does not already exists, meaning that the regex pam_mkhomedir is not already present.
- name: Ensure home directories are created upon login
lineinfile:
path: /etc/pam.d/common-session
regexp: 'pam_mkhomedir'
insertafter: 'pam_sss'
line: 'session required pam_mkhomedir.so skel=/etc/skel/ umask=0022'
tags:
- ldap
- pam
- config
Related
I am building ansible-core project, but due to following code snipped getting error
# This was necessary to prevent errors when upgading conan from an earlier to a newer version, as the accepted file format changed.
- name: Make conan storage path absolute
lineinfile:
path: '{{ HOME }}/.conan/conan.conf'
regexp: '^path ='
line: path = ./data
Error-
TASK [Make conan storage path absolute] ****************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Destination /home/developer/.conan/conan.conf does not exist !", "rc": 257}
I tried commenting that part and was able to build but not sure whether to remove that code snippet
I have resolved issue by changing path from
'{{ HOME }}' to '~'
# This was necessary to prevent errors when upgading conan from an earlier to a
newer version, as the accepted file format changed.
- name: Make conan storage path absolute
lineinfile:
path: '{{ HOME }}/.conan/conan.conf'
regexp: '^path ='
line: path = ./data
I have tried something like this
- name: Create a directory
ansible.builtin.file:
path: /etc/fail2ban
state: directory
mode: '0755'
and I am a getting a error
fatal: [localhost]: FAILED! => {"changed": false, "msg": "There was an issue creating /etc/fail2ban as requested: [Errno 13] Permission denied: b'/etc/fail2ban'", "path": "/etc/fail2ban"}
I am trying to create a directory on a remote server.
Need Help !!!
Thanks in advance.
Have you already tested the execution with become: yes?
- name: Create a directory
ansible.builtin.file:
path: /etc/fail2ban
state: directory
mode: '0755'
become: yes
See the Ansible docs for more information on become and privilege escalation.
Otherwise the output of stat might help you to understand what is going on. You could add the following two tasks before your file task:
- name: Get file stat
stat:
path: /etc/fail2ban
register: stat_result
- name: Print file stat
debug:
var: stat_result
I am trying to take running config back up from two nexus switches, what am I missing from below
configuration?
- name: copy nexus switch running configurations
hosts: nxos-devices
gather_facts: no
ignore_errors: yes
tasks:
- name: timestamp
local_action: command date +%Y%m%d
register: timestamp
- name: get running configuration from nexus switch
nxos_config: running_config
register: running_config
- copy:
content: "{{ running_config.stdout[0] }}"
dest: ".config/{{ item.hostname }}_{{ timestamp.stdout }}.txt"
with_items:
- { hostname: bur1-mrt1 }
- { hostname: bur1-mrt2 }
Getting below error
[root#ansible-net-001 bkrishna]# ansible-playbook -i hosts running-config.yml
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this will change, but
still be user configurable on deprecation. This feature will be removed in version 2.10. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
ERROR! this task 'nxos_config' has extra params, which is only allowed in the following modules: shell, win_shell, include_vars, add_host, raw, include_role, meta, set_fact, include, import_tasks, script, import_role, include_tasks, group_by, command, win_command
The error appears to be in '/root/ansible/bkrishna/running-config.yml': line 12, column 7, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: get running configuration from nexus switch
^ here
I am using Ansible 2.8.1 to download from Nexus.
I want to register a variable so that in subsequent tasks, I will know what file I downloaded by looking at downloaded_file.dest.
- name: Download assembly file to /my/server/location/
get_url:
url: https://nexus.mycompany.com/service/rest/v1/search/assets/download?repository=repo-snapshots&group=group&name=name&sort=version&direction=desc
validate_certs: no
dest: /my/server/location/
force: yes
register: downloaded_file
But when running ansible-playbook 2.8.1
I get
fatal: [myserver]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (get_url) module: register Supported parameters include: attributes, backup, checksum, client_cert, client_key, content, delimiter, dest, directory_mode, follow, force, force_basic_auth, group, headers, http_agent, mode, owner, regexp, remote_src, selevel, serole, setype, seuser, sha256sum, src, timeout, tmp_dest, unsafe_writes, url, url_password, url_username, use_proxy, validate_certs"}
So it's considering the register as a parameter to get_url. Is my syntax correct here? How do I get the return values from the task?
The syntax is wrong. register is not a parameter of get_url. It's a task's level directive.
Correct
- name: Download assembly file to /my/server/location/
get_url:
url: https://nexus.mycompany.com/service/rest/v1/search/assets/download?repository=repo-snapshots&group=group&name=name&sort=version&direction=desc
validate_certs: no
dest: /my/server/location/
force: yes
register: downloaded_file
I am following this page, Clone a private git repository with Ansible (using password prompt) to solve my requirement. Re-used the same template in my playbook main.yml whose contents are as
---
- name: move CentOS repo definitions outside temp
copy:
src: "{{ item }}"
dest: /etc/yum.repos.d/
owner: "root"
mode: 0600
with_fileglob:
- /etc/yum.repos.d/temp/*
become: true
- name: passing git credentials for cloning the repos
vars_prompt:
- name: "githubuser"
prompt: "Enter your github username"
private: no
- name: "githubpassword"
prompt: "Enter your github password"
private: yes
and some more below. Am facing an error
The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: passing git credentials for cloning the repos
^ here
The error appears to have been in '/tmp/.../tasks/main.yml': line 12, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: passing git credentials for cloning the repos
^ here
I validated the yml using the syntax check option available
ansible-playbook main.yml --syntax-check
and also on the YAML lint, but can't seem to find the reason why the error is seen.
You can't use vars_prompt at task level, only at playbook level.
If your main.yml is a part of role, you should move prompt block to upper level playbook that includes your role.