大网数据广告活动
服务器运维问答

Why am I getting this error from Ansible when trying to change the permissions on a file?

· 52CE 我爱测

I have the following task in a role named tomcat: - name: copy tomcat file settings copy: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: tomcat group: tomcat mode: "{{ item.mode }}" with_items: - { src: logrotate-tomcat7, d…

问题原文

原帖链接 · LegendaryDude · CC BY-SA 3.0

I have the following task in a role named tomcat:

- name: copy tomcat file settings
  copy:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: tomcat
    group: tomcat
    mode: "{{ item.mode }}"
  with_items:
  - { src: logrotate-tomcat7, dest: /etc/logrotate.d/tomcat7, mode: 0644 }
  - { src: keystore.pks, dest: /var/lib/tomcat7/webapps, mode: 0644  }
  - { src: jmxremote.access, dest: /etc/tomcat7, mode: 0644   }
  - { src: jmxremote.password, dest: /etc/tomcat7, mode: 0600 }

When I run the playbook that calls the tomcat role, I see the following output:

TASK [devops-server : copy tomcat file settings] *********************************
changed: [10.71.10.11] => (item={u'dest': u'/etc/logrotate.d/tomcat7', u'src': u'logrotate-tomcat7', u'mode': 420})
changed: [10.71.10.11] => (item={u'dest': u'/var/lib/tomcat7/webapps', u'src': u'keystore.pks', u'mode': 420})
changed: [10.71.10.11] => (item={u'dest': u'/etc/tomcat7', u'src': u'jmxremote.access', u'mode': 420})
failed: [10.71.10.11] (item={u'dest': u'/etc/tomcat7', u'src': u'jmxremote.password', u'mode': 384}) => {"checksum": "2203ad1530a3bc06732043ba67d129b5364505ce", "details": "bad symbolic permission for mode: 384", "failed": true, "gid": 91, "group": "tomcat", "item": {"dest": "/etc/tomcat7", "mode": 384, "src": "jmxremote.password"}, "mode": "0644", "msg": "mode must be in octal or symbolic form", "owner": "tomcat", "path": "/etc/tomcat7/jmxremote.password", "size": 52, "state": "file", "uid": 91}
...ignoring

Obviously, mode 0600 works on the command line of my EC2 instance:

ec2-user@devops-01 ~]$ sudo chmod 0600 /etc/tomcat7/jmxremote.password
ec2-user@devops-01 ~]$ ls -l /etc/tomcat7/jmxremote.password
-rw------- 1 tomcat tomcat 52 Oct 28 16:18 /etc/tomcat7/jmxremote.password

So what gives? Is this an Ansible bug or am I missing something?

已采纳解答

原帖链接 · Henrik Pingel · CC BY-SA 3.0

This is obviously a bug in Ansible. To me the code seems fine. According to this GitHub Issue the error can be worked around by setting the octal for modeas a string. Like this: 0644 "0644"

So I would try this:

with_items:
 - { src: logrotate-tomcat7, dest: /etc/logrotate.d/tomcat7, mode: "0644" }

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。